I'm not sure if I have the jargon for asking this question not being a web developer but please bear with me.
I want to send parameters to a client side HTML page (just a file on a disk no web server involved). My initial attempt was to use a query string and then parse it from window.location.href
but instead of the query string being passed to the page I get a file not found error.
Is it possible to do what I'm attempting?
You might want to pass parameters using the # instead of ? on local files.
Firefox and Chrome will let you do this. But IE won't. IE returns file not found like you said.
file:///D:/tmp/test.htm?blah=1
<script language='javascript'>
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
alert(getUrlVars());
</script>
do you mean you want something like
window.location.search
http://developer.mozilla.org/En/DOM/Window.location
search: the part of the URL that follows the ? symbol, including the ? symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With