Last active
August 29, 2015 14:07
-
-
Save ethyde/b5ccd98427836e3351c7 to your computer and use it in GitHub Desktop.
Parse url param : http://stackoverflow.com/a/3855394
Use window.location with jQuery : http://stackoverflow.com/a/14613849
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
// in iframe | |
var isInIframe = (window.location != window.parent.location) ? true : false; | |
// or | |
var isIniFrame = function(){ | |
return (window.location != window.parent.location) ? true : false; | |
}; |
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
(function($) { | |
$.QueryString = (function(a) { | |
if (a === "") return {}; | |
var b = {}; | |
for (var i = 0; i < a.length; ++i) | |
{ | |
var p=a[i].split('='); | |
if (p.length != 2) continue; | |
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); | |
} | |
return b; | |
})(window.location.search.substr(1).split('&')); | |
})(jQuery); | |
// example.com?param1=name¶m2=&id=6 | |
$.QueryString["param1"]; //name |
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
// URL testée http://www.refulz.com:8082/index.php#tab2?foo=123 | |
/* | |
* Property Result | |
* ------------------------------------------- | |
* host www.refulz.com:8082 | |
* hostname www.refulz.com | |
* port 8082 | |
* protocol http | |
* pathname index.php | |
* href http://www.refulz.com:8082/index.php#tab2 | |
* hash #tab2 | |
* search ?foo=123 | |
*/ | |
// Usage | |
// var x = $(location).attr('<property>'); | |
// Exemple | |
var hostname = $(location).attr('hostname'); // www.refulz.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment