简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM