Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从html页面访问查询字符串/参数_Html_Query String - Fatal编程技术网

从html页面访问查询字符串/参数

从html页面访问查询字符串/参数,html,query-string,Html,Query String,我有一个基本的html页面,其中有一个查询参数被传递到该页面。我以为我可以通过Request.QueryString获得值,但我正在做的更多阅读似乎表明这仅适用于asp应用程序。我的html如下所示 <body> <object type="application/pdf" width="100%" height="100%"> <!--This didn't work--> <param name="src" v

我有一个基本的html页面,其中有一个查询参数被传递到该页面。我以为我可以通过Request.QueryString获得值,但我正在做的更多阅读似乎表明这仅适用于asp应用程序。我的html如下所示

<body>
    <object type="application/pdf" width="100%" height="100%">
        <!--This didn't work-->
        <param name="src" value="<%=Request.QueryString["path"]%>" />
        <!--Neither did this-->
        <!--<param name="src" value="<%=Request.Params["path"]%>" />-->
        <!--When it is hardcoded then my page is displaying the pdf as expected.-->
        <!--<param name="src" value="scan.pdf" />-->
    </object>
</body>

我正在调用displayPdf.htm?path=scan.pdf的页面

我一直在寻找一种无需编写javascript解决方案就可以访问html中的查询参数的方法,但运气不好。我确信添加一个js函数不会有什么大不了的,我只是想,如果采用单行方法,我会避免它


感谢您的帮助。

这不能用纯HTML完成

这可以通过两种方式完成,使用JavaScript:

<body><script>
var param = /[&?]path=([^&]+)/.exec(location.search);
param = param ? param[1].replace(/"/g, '&quot;') : '';
document.write('<object type="application/pdf" width="100%" height="100%">\n' +
    '<param name="src" value="' + param + '" />\n</object>');
</script></body>

var param=/[&?]path=([^&]+)/.exec(location.search);
param=param?参数[1]。替换(/“/g,”):“”;
document.write('\n'+
“\n”);
另一种方法是使用DOM(demo:)填充参数:


    
var param=/[&?]path=([^&]+)/.exec(location.search);
如果(参数)
document.getElementById('param-path')。value=param[1];
​

在任何一种情况下,都会从属性中读取查询字符串,并使用一个简单的正则表达式进行解析。

第二种样式几乎适用于我,但javascript块会在对象存在之前被调用。如果我能在之后再打电话给它,那么这个解决方案肯定会对我有效。不过,第一种方法确实有效,没有任何变化。非常感谢。
<body><object type="application/pdf" width="100%" height="100%">
    <param name="src" value="" id="param-path" />
</object>
<script>
var param = /[&?]path=([^&]+)/.exec(location.search);
if (param)
    document.getElementById('param-path').value = param[1];
</script>​</body>