0

奇妙な問題があります。一部のブラウザー (chrome など) では、以下のコードで新しいウィンドウが開きます。したがって、期待どおりに機能します。他のブラウザー (firefox など) では、アラート ボックスが表示されるだけなので、要求されたウィンドウは開きません。すべてのブラウザで動作するコードの提案はありますか?

if(TestVar == "1810" ) 
            {
                alert ("test  " + TestVar + "! ");
                window.location.href="http://astyle.home.xs4all.nl/beautyfarm2003/wellnessbon_321442.html";
            }

if(TestVar == "1920" ) 
            {
                alert ("Test " + TestVar + "! "); 
                window.location="http://astyle.home.xs4all.nl/beautyfarm2003/wellnessbon_1925485.html";
            }  // Vriendinnendag
4

1 に答える 1

0

このコードは、Chrome、Internet Explorer 9/10、および Firefox で問題なく動作するようです。

以下を試してください: http://jsbin.com/uluziz/edit#javascript,html

新しいウィンドウを開きたい場合は、変更していませんwindow.location現在のウィンドウの場所を変更するだけです。代わりに使用window.open()して、新しいウィンドウを開いて新しい場所に移動します。

var myWin = window.open('http://stackoverflow.com','SO','width=640,height=480');

setTimeout(function(){
  myWin.close();
}, 2000);

デモ: http://jsbin.com/ekoluk/3/edit

于 2012-05-03T14:55:27.707 に答える