2011-11-08 46 views
10

點擊電子郵件中的動態鏈接後,我的用戶登陸頁面上預填像這樣的形式:如何在Javascript重定向上保留URL參數?

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來做所有事情。

回答

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