2009-09-16 6 views

答えて

1
function dropdown(mySel) { 
    var myVal = mySel.options[mySel.selectedIndex].value; 
    if (myVal) { 
     if (mySel.form.target) { 
      window.open(myVal, mySel.form.target, '_attributes_'); 
     } else { 
      window.location.href = myVal; 
     } 
    } 
    return false; 
} 

事前に

<SCRIPT TYPE="text/javascript"> 
<!-- 
function dropdown(mySel) 
{ 
var myWin, myVal; 
myVal = mySel.options[mySel.selectedIndex].value; 
if(myVal) 
    { 
    if(mySel.form.target)myWin = parent[mySel.form.target]; 
    else myWin = window; 
    if (! myWin) return true; 
    myWin.location = myVal; 
    } 
return false; 
} 
//--> 
</SCRIPT> 

<div id=countryselector> 
    <FORM 
     ACTION="../cgi-bin/redirect.pl" 
     METHOD=POST onSubmit="return dropdown(this.gourl)"> 
     <SELECT NAME="gourl"> 
      <OPTION VALUE="">Select a Country... 
      <OPTION VALUE="http://google.com">USA 
      <OPTION VALUE="http://google.ca">Canada 
     </SELECT> 
     <INPUT TYPE=SUBMIT VALUE="Go"> 
    </FORM> 
</div> 

おかげで_attributes_のリストはhere for Mozillaまたはhere for IEを見つけることができます。利用可能なオプションにはいくつかの違いがありますので、両方のリストを確認することをお勧めします。

また、関数呼び出しオフ三番目のパラメータを残すことができますし、それはあなたの<form>target="_blank"のように振る舞う必要があります:開くために提供されるリンクで文書化されているようにここで

// behaves as if you submitted <form ... target="_blank">: 
window.open(myVal, mySel.form.target); 

_attributes_のセットを使用した例であります抑制UIの特定の部分で特定のサイズと位置の窓:私はそれを動作させることはできません

// this opens a window that is 400 pixels by 300 pixels 
// it is positioned 100 pixels from the top and the left 
// it will have no statusbar, no menu but the new window will have a toolbar: 
window.open(myVal, mySel.form.target, 
    'height=300,width=400,top=100,left=100,statusbar=0,menu=0,toolbar=1'); 
+0

... それはこのように見えるようになっている: 関数のドロップダウン(mySel){ var myVal = mySel.options [mySel.selectedIndex] .value; (myVal、mySel.form.target、 'target = "_ blank"'); if } else { window.location.href = myVal; } } falseを返します。 } – BassKozz

+0

@BassKozz:いいえ '_attributes_'は' 'statusbar = 0、menu = 0、top = 10、left = 10''のようなものです(新しいウィンドウにはステータスバーがありません。メニューはありません。上から、左からピクセル)。 –

+0

作業していません... window.open(myVal、mySel.form.target); リンクを同じウィンドウで開いています。 – BassKozz

関連する問題