2017-10-02 6 views
0

私はcondizionale自動リダイレクトURLのために書いていますが、動作しません。私はまだ発表されたように、なぜ、このの誰もが機能しない、他のURLから自動リダイレクトする方法は?

<script> 
     function mobileDevice() 
     { 
     $type = $_SERVER[‘HTTP_USER_AGENT’]; 
     if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false) 
     return true; 
     else 
     return false; 
     } 
     if(mobileDevice() == true) 
     header(‘Location: https://www.organization.org/mobile/index_mobile.htm‘); 
</script> 

<script type="text/javascript"> 
     if (screen.width <= 414) { 
     document.location = "index.htm"; 
     <script language=javascript> 
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
     location.replace("https://www.organization.org/mobile/index_mobile.htm"); 
    } 
      </script> 
     } 
    </script> 

:私は2つの方法で試してみましたか?

答えて

1

プレーンJavaScriptでは、リダイレクトするメソッドを使用する代わりに、値の場所を割り当てる必要があります。 は、URLの変更履歴を保存しませんメソッドを置き換えます。

window.location = "https://www.organization.org/mobile/index_mobile.htm"; 

また、2つ目のアプローチでは2つのタグをネストします。正しいコードは次のようになります。

<script type="text/javascript"> 
     if (screen.width <= 414) { 
     document.location = "index.htm"; 
     if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { 
      location.replace("https://www.organization.org/mobile/index_mobile.htm"); 
     } 
     } 
</script> 
+0

私がしようとした場合: とにかく動作しません –

+1

スクリプトブロック内にメタタグを挿入することはできません。これはどのように動作するのではありません。メタタグはheadタグの内側にある必要があります。実行されるコードでスクリプトタグを追加できますが、その内部にはJavaScriptだけが含まれています。 '「 – jmtalarn

+0

ああ...だからこそ。どうもありがとうございます! –

関連する問題