【问题标题】:Can I pass a <script> into a meta refresh URL without php?我可以在没有 php 的情况下将 <script> 传递到元刷新 URL 吗?
【发布时间】:2015-07-15 06:36:07
【问题描述】:

希望有人可以帮助我。

我需要将 url 中的令牌传递到我的页面,更具体地说是元刷新 url。

这是我目前所拥有的:

<script>
function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
    );
}
</script>

<meta http-equiv="refresh" content="0;url=http://redirect.com/?subid=<script>document.write(getURLParameter('subid'))</script>">

正如您在 content= 部分中看到的,我正在尝试使用以下脚本将我的 url 中的令牌传递到 subid= 中:

<script>document.write(getURLParameter('subid'))</script>

但由于它包含 content=" " 引号,因此无法识别脚本。我也尝试了以下方法,但它也不起作用:

"+getURLParameter('subid')+"

我已经使用 php 完成了这个工作,但是这个文件将托管在 CDN 上,所以我可以在那里运行任何 php 代码。

有人对如何做到这一点有一些建议吗?

如果我没有正确解释这一点,我深表歉意,但我并不像你想象的那样精通这个领域。

谢谢。 :)

【问题讨论】:

    标签: php


    【解决方案1】:

    没有。您不能在其他 HTML 标记的属性中嵌套 HTML 标记,甚至不能嵌套 &lt;script&gt; 标记。

    但是,您可以做的是使用 Javascript 直接执行重定向,例如

    window.location = "http://example.com/?subid=" + getURLParameter("subid");
    

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 2012-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多