wiitohzjeh
wiitohzjeh

Reputation: 347

Passing and capture url variables jQuery without php

was trying to finish a script in jquery and I was stuck. after giving several times, I did not succeed. I need to pass the variables in the url but without using php, that is, for example:

http://domain.tld/#var=1&anothervar=2

the truth, do not know how to "capture" these values with jquery, without first going through php... thanks in advance.

Upvotes: 1

Views: 1532

Answers (2)

Glavić
Glavić

Reputation: 43552

function getUrlParam(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&#]"+name+"=([^\\?&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    return results == null ? '' : results[1];
}

Pure javascript...

Upvotes: 2

user920041
user920041

Reputation:

You can catch and handle url locations with jquery and the hashchange() plugin: http://benalman.com/projects/jquery-hashchange-plugin/

Or for more advanced use with a lot of links like this, look into backbone.js url routing: http://documentcloud.github.com/backbone/#Router

Upvotes: 0

Related Questions