Skip to content

Instantly share code, notes, and snippets.

@ethyde
Last active August 29, 2015 14:07
Show Gist options
  • Save ethyde/b5ccd98427836e3351c7 to your computer and use it in GitHub Desktop.
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
// in iframe
var isInIframe = (window.location != window.parent.location) ? true : false;
// or
var isIniFrame = function(){
return (window.location != window.parent.location) ? true : false;
};
(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&param2=&id=6
$.QueryString["param1"]; //name
// 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