5

モバイルページでない限り、正常に実行できるクエリ文字列を使用しようとしています。私がやっていることは、それがモバイルであるかどうかを確認してリダイレクトすることです。クエリ文字列をリダイレクト 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>
4

1 に答える 1

9

これはあなたが望むものかもしれないと思います..

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 はそのまま残ります。

于 2013-05-17T21:48:53.990 に答える