Frage

Ich habe einen Drop-Down-Wähler an Ort und Stelle, und ich brauche, es zu ändern, so dass das target = „_ blank“, so dass es einen neuen Tab öffnet.

Hier ist der aktuelle Code:

<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>

Vielen Dank im Voraus

War es hilfreich?

Lösung

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;
}

Eine Liste von _attributes_ gefunden werden hier für Mozilla oder hier für IE . Es gibt ein paar Unterschiede in einige der Optionen zur Verfügung, so ist es am besten, beiden Listen zu überprüfen.

Sie können auch den dritten Parameter von dem Funktionsaufruf verlassen und es sollte wie target="_blank" auf Ihrem <form> verhalten:

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

Hier ist ein Beispiel einen Satz von _attributes_ verwendet, wie bei den Verbindungen dokumentiert bereitgestellt ein Fenster mit einer bestimmten Größe zu öffnen, und die Position mit spezifischen Teilen der UI unterdrückt:

// 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');
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top