最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Jun 15, 2009 at 18:23 Motti asked Jun 15, 2009 at 6:17 MottiMotti 115k56 gold badges194 silver badges273 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 10

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.

发布评论

评论列表(0)

  1. 暂无评论