Skip to content

Instantly share code, notes, and snippets.

@ktzar
Created November 9, 2016 10:28
Show Gist options
  • Save ktzar/21b0b7eff3240be54ca35fe09f9e1774 to your computer and use it in GitHub Desktop.
Save ktzar/21b0b7eff3240be54ca35fe09f9e1774 to your computer and use it in GitHub Desktop.
Test using anchor tag to parse URL
<style>
body {
font-size: 90px;
text-align: center;
color: white;
}
</style>
<div id="result"></div>
<script>
window.onload = function () {
var result = document.getElementById("result");
var a = document.createElement("a");
a.href = "http://www.somedomain.com/somePath?somequery=string#andAHash?hello";
a.search += "&andAnotherOne";
if (a.href === "http://www.somedomain.com/somePath?somequery=string&andAnotherOne#andAHash?hello") {
result.style.backgroundColor = "green";
result.innerHTML = "CORRECT";
} else {
result.style.backgroundColor = "red";
result.innerHTML = "ERROR";
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment