Possible Duplicate:
Pass vars to JavaScript via the SRC attribute
May I know how to read get the p value on js file link like filename.js?p=value with local javascript in the js file? Any function to work like the $_GET['p'] in php? Thanks.
Possible Duplicate:
Pass vars to JavaScript via the SRC attribute
May I know how to read get the p value on js file link like filename.js?p=value with local javascript in the js file? Any function to work like the $_GET['p'] in php? Thanks.
try this:
var tmp = location.href, it;
if (q) it = tmp.substr(q + 1).split('&');
else it = '';
for (var i in it) {
var t = it[i].split('=');
if (t[0] == 'p') {
//do something
break;
}
}
window.location point to the location of the document that loaded the current script. OP wants to extract the query string of the script file itself (as loaded from the HTML document).function _GET( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
This will do the equivalent in javascript.
window.location.searchto extract the query string from the current request url. But that is completely different than a query string to a javascript file.