如何在Javascript重定向上保留URL参数? [英] How to keep URL parameters on Javascript redirect?

查看:96
本文介绍了如何在Javascript重定向上保留URL参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击电子邮件中的动态链接后,我的用户会登陆一个页面,其中包含预先填充的表单:

After clicking a dynamic link in an email, my users land on a page with a form pre-populated like this:

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

脚本一开始就运行,将它们重定向到页面的移动版本:

A script runs right at the beginning to re-direct them to a mobile version of the page:

<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>

有没有办法在重定向时保留这些参数?

Is there any way to keep those parameters when they are redirected like that?

我知道有更好的方法可以使用PHP进行移动重定向,但我公司的服务器对于让我的部门目录提供PHP文件非常粗略,因此我们尝试使用Javascript完成所有工作。

I know there are better ways to mobile-redirect with PHP, but my company's server is sketchy about letting my department's directory serve PHP files, so we try to do everything with Javascript.

推荐答案

document.location.search

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

can be used to append current location query strings to string in 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>

这篇关于如何在Javascript重定向上保留URL参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆