Created
February 25, 2013 20:23
-
-
Save danro/5032951 to your computer and use it in GitHub Desktop.
neat href tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example window url: http://test.dev/stuff | |
var query = 'poop=butts&farts=smellz'; | |
var parser = document.createElement('a'); // create anonymous 'a' tag | |
parser.href = window.location.href; | |
parser.search = query; | |
console.log(parser.href); | |
// ^ should output: http://test.dev/stuff?poop=butts&farts=smellz | |
parser.pathname += '.json'; | |
console.log(parser.href); | |
// ^ should output: http://test.dev/stuff.json?poop=butts&farts=smellz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment