向URL重定向添加查询字符串

Add query string to URL redirect

本文关键字:查询 字符串 添加 重定向 URL      更新时间:2023-09-26

我试图使用查询字符串,我可以成功做到,除非它是一个移动页面。我正在做的是检查它是否移动和重定向。是否有办法将查询字符串附加到重定向url?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript">// <![CDATA[  
    var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows'sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) {  
        document.location = "http://www.xxxxxxx.com/mobile";  
    }  
// ]]></script> 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xxxxxxxxx</title>
<script type="text/javascript">
    window.onload = function(){
        var total = 0;
        for(var x = 0; x < parameters.length; x++){
            document.getElementById("customerID").value = parameters[x].value;
        }
        document.forms[0].onsubmit = validate;  
    }
</script>

我想这可能是你想要的。

var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows'sce|palm/i.test(navigator.userAgent.toLowerCase()));  
if (mobile) {
  window.location = "http://www.xxxxxxx.com/mobile" + window.location.search + window.location.hash;
}

我将其简化为window.location.search是一个空白字符串或以?开头。.hash

也是一样

如果您的起始URL是http://www.some.com/entry?id=10,那么重定向将是http://www.some.com/mobile?entry?id=10

哈希

也是一样

http://www.some.com/entry?id=10 paragraph2会重定向到http://www.some.com/mobile?id=10 paragraph2

如果当前URL不包含任何一个,则重定向URL将保持原样