[英]function GetURLParameter(sParam) is returning %20 as white space on page
[英]getURLParameter For landing page
我正在尝试在目标网页上显示url参数,但无法正常工作。
<script> function getURLParameter(name) { return decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] || '' ); } </script> <br> <h1><b>Your <script>document.write(getURLParameter("devicebrand") + (" ") + getURLParameter("devicemodel"))</script>might be infected with <span id="blink"> (6)</span>Viruses!</b></h1>
我在目标网页上看到的是:
您可能感染了病毒
当我用以下命令强制url中的值时:
这是网址
www.domain.com/page.html?devicebrand=Apple&devicemodel=Iphone
什么都没发生
任何帮助是极大的赞赏
如果我确定我可以传递一些东西并在页面加载时运行,那么对我有用。 不要使用document.write
也不要吓people人。
function getURLParameter(name, srch) { srch = srch || location.search; return decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(srch) || [, null])[1] || '' ); } window.onload = function() { var loc = "#devicebrand=iPhone&devicemodel=6S"; document.getElementById("devicebrand").innerHTML = getURLParameter("devicebrand", loc) document.getElementById("devicemodel").innerHTML = getURLParameter("devicemodel", loc) }
<br> <h1><b>Your <span id="devicebrand"></span> <span id="devicemodel"></span> might be infected with <span id="blink"> (6)</span>Viruses!</b></h1>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.