[英]Add query string to URL redirect
I am trying to use a query string which I can successfully do unless it is a mobile page. 我试图使用一个我可以成功做的查询字符串,除非它是一个移动页面。 What I am doing is checking if it is mobile and redirecting.
我正在做的是检查它是否是移动和重定向。 Is there a way to attach the query string to the redirect 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>
I think this might be what you want.. 我想这可能就是你想要的......
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;
}
I simplified this as window.location.search is either a blank string or starts with ?. 我将其简化为window.location.search是一个空字符串或以?开头。 Same goes for .hash
同样适用于.hash
If your starting URL was http://www.some.com/entry?id=10 the redirect would be http://www.some.com/mobile?entry?id=10 如果您的起始网址为http://www.some.com/entry?id=10,则重定向将为http://www.some.com/mobile?entry?id=10
Same goes for hashes 哈希也是如此
http://www.some.com/entry?id=10#paragraph2 would redirect to http://www.some.com/mobile?id=10#paragraph2 http://www.some.com/entry?id=10#paragraph2将重定向到http://www.some.com/mobile?id=10#paragraph2
If the current URL does not contain either the redirect URL will remain as is. 如果当前URL不包含重定向URL将保持原样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.