أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
var urlPath = window.location.pathname.split( '/' );
then just do some string parsing on urlPath variable...
Hi Zaid,
Here is the small javascript function which can take variable as parameter
function getQuerystring(key)
{
key = key.replace(/[\\[]/,"\\\\\\[").replace(/[\\]]/,\\\\\\]);
var regex = new RegExp("[\\\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
alert("no Q string found...");
else alert(qs[1]);
}
WE can get string values by using alert box("message")
var query = window.location.search;
JQUERY:
http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
Google :
function(b){var c =typeof b ==="undefined";if(a !== h && c)return a;for(var d ={}, b = b || k[B][vb], e = b[p]("?"), f = b[p]("#"), b =(f ===-1? b[Ya](e +1):[b[Ya](e +1, f - e -1),"&", b[Ya](f +1)][K](""))[z]("&"), e = i.dd ? ia : unescape, f =0, g = b[w]; f < g;++f){var l = b[f][p]("=");if(l !==-1){var q = b[f][I](0, l), l = b[f][I](l +1), l = l[Ca](/\\+/g," ");try{ d[q]= e(l)}catch(A){}}} c &&(a = d);return d }
JS :
function getParameterByName(name){ name = name.replace(/[\\[]/,"\\\\\\[").replace(/[\\]]/,"\\\\\\]");var regex =newRegExp("[\\\\?&]"+ name +"=([^&#]*)"), results = regex.exec(location.search);return results ==null?"": decodeURIComponent(results[1].replace(/\\+/g," "));}
document.write(location.search);
Hello Zaid,
Just split up the parameters into an associative-array style:
var urlParams;
(window.onpopstate = function () {
var match,
pl = /\\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
Example querystring:
?i=somemore&mode=xxxx&sid=123456&enc=+Voala%20&empty
Result:
urlParams = {
enc: "Voala",
i: "somemore",
mode: "xxxx",
sid: "123456",
empty: ""
}
alert(urlParams["mode"]);
// -> "front"
alert("empty" in urlParams);
// -> true
Server-side preprocessing with PHP and native JSON functions.
<script>var urlParams = <?php echo json_encode($_GET, JSON_HEX_TAG);?>;</script>
I found a best example for this. Please have a look on following URL: