1

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.

1
  • Do you wan't to strip the arguments from the current url or add them into the url? Commented Nov 26, 2011 at 17:16

2 Answers 2

2
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...

Sign up to request clarification or add additional context in comments.

2 Comments

and.. how to use? y try with the url: domain.tld/#var=example var urlup = getUrlParam(var); document.write(urlup); and no work.. :/
getUrlParam("STRING"); in your case getUrlParam('var');
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.