Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Last active November 4, 2016 19:16
Show Gist options
  • Save wilcorrea/a2e85f78c5ab20546681c0ac2f68cfe0 to your computer and use it in GitHub Desktop.
Save wilcorrea/a2e85f78c5ab20546681c0ac2f68cfe0 to your computer and use it in GitHub Desktop.
<script>
function $_GET(name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)");
const results = regex.exec(url);
if (!results) {
return null;
}
if (!results[2]) {
return '';
}
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
</script>
<script>
const code = $_GET('page');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment