Created
October 14, 2014 10:03
-
-
Save vlrmprjct/1bb5e9c4e860dd971b98 to your computer and use it in GitHub Desktop.
How to get current url in JavaScript and jQuery ?
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
var testurl = http://www.test.com:8082/index.php#tab2?foo=123 | |
// In Javascript: | |
window.location.host www.test.com:8082 | |
window.location.hostname www.test.com | |
window.location.port 8082 | |
window.location.protocol http | |
window.location.pathname index.php | |
window.location.href http://www.test.com:8082/index.php#tab2 | |
window.location.hash #tab2 | |
window.location.search ?foo=123 | |
// In jQuery: | |
$(location).attr('host'); www.test.com:8082 | |
$(location).attr('hostname'); www.test.com | |
$(location).attr('port'); 8082 | |
$(location).attr('protocol'); http | |
$(location).attr('pathname'); index.php | |
$(location).attr('href'); http://www.test.com:8082/index.php#tab2 | |
$(location).attr('hash'); #tab2 | |
$(location).attr('search'); ?foo=123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment