【问题标题】:How to keep URL parameters on Javascript redirect?如何在 Javascript 重定向中保留 URL 参数?
【发布时间】:2011-12-24 17:49:02
【问题描述】:

单击电子邮件中的动态链接后,我的用户会进入一个预先填充了如下表单的页面:

http://www.test.com/november_promo/default.html?Name=Test&Email=Test.com

一个脚本会在开头运行,将它们重定向到页面的移动版本:

<script type="text/javascript" src="redirection_mobile.min.js"></script>
<script type="text/javascript">
SA.redirection_mobile ({param:"isDefault", mobile_url: "www.test.com/november_promo/default_mobile.html", mobile_prefix : "http://", cookie_hours : "1" });
</script>

当这些参数被这样重定向时,有什么方法可以保留这些参数?

我知道使用 PHP 进行移动重定向有更好的方法,但我公司的服务器对于让我部门的目录服务 PHP 文件的做法很粗略,所以我们尝试使用 Javascript 来做所有事情。

【问题讨论】:

    标签: javascript url redirect parameters


    【解决方案1】:
    document.location.search
    

    可用于将当前位置查询字符串附加到 javascript 中的字符串

    例如

    <script>
    var uri = 'foobar.html';
    
    // while current location is 'baz.html?foo=1&a=b' for example
    
    uri = uri + document.location.search;
    
    // this will output 'foobar.html?foo=1&a=b'    
    alert(uri);
    
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-22
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      • 2012-12-26
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      相关资源
      最近更新 更多