Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass parameters to a client-side HTML page?

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?

like image 890
Motti Avatar asked Jun 15 '09 06:06

Motti


3 Answers

You might want to pass parameters using the # instead of ? on local files.

like image 186
jensgram Avatar answered Sep 30 '22 04:09

jensgram


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>
like image 36
Jack B Nimble Avatar answered Sep 30 '22 03:09

Jack B Nimble


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.

like image 25
nonopolarity Avatar answered Sep 30 '22 03:09

nonopolarity