I need to parse the query string www.mysite.com/default.aspx?dest=aboutus.aspx
.
How do I get the dest
variable in JavaScript?
views:
586answers:
5You need to use the location.search
property.
Here is some sample code to parse it.
Here's a script that might help: http://adamv.com/dev/javascript/querystring
Basically you end up parsing document.location.
Here is a fast and easy way of parsing QueryString
in Javascript.
<script>
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
alert('Query Variable ' + variable + ' not found');
}
</script>
Now make a request to page.html?x=Hello
<script>
alert(getQueryVariable("x"));
</script>
Source : http://tinyurl.com/4yfr28
Use the parseQueryString.js Javascript function found here:
safalra.com/web-design/javascript/parsing-query-strings/
In your example, if you wanted to test the parsing of the "dest" variable for the URL: www.mysite.com/default.aspx?dest=aboutus.aspx then you can try: http://urlparser.com/?url=www.mysite.com/default.aspx?dest=aboutus.aspx
Have a look at this solution. Using his function, you would just not to call gup('dest')
to grab the URL dest
parameter.