Archivio della categoria: javascript

Leggere le variabili GET in javascript

Snipplet per leggere le variabili GET in Javascript

function GET(q,s)
{
s = s ? s : window.location.search;
var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i');
return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}

Esempio:

// http://test.com/index.php?v=test
var var1 = GET('v');

alert(var1);

Ho trovato questa ottima funzione qui
Credits tuttavia andava fixata la regex, per questo la posto.

Get Root – Find iframe parent location

This function is useful to determinate information about the page who host an iframe from the iframe.

function get_root(obj, current_ref) {
if(obj.parent.location.href != current_ref) {
return get_root(obj.parent, obj.location.href);
}
else {
return obj.location.href;
}
}

Usage:

get_root(window, window.location.href)

Credits to: 3xlstudio

http://snipplr.com/view/60285/ifram-get-parent/