Question

J'ai un sélecteur de liste déroulante en place et je dois le modifier de sorte que le paramètre target = " _blank " il ouvre donc un nouvel onglet.

Voici le code actuel:

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

Merci d'avance

Était-ce utile?

La solution

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

Une liste de _attributs _ peut être trouvée ici pour Mozilla ou ici pour IE . Il existe quelques différences dans certaines des options disponibles, il est donc préférable de consulter les deux listes.

Vous pouvez également laisser le troisième paramètre désactivé dans l'appel de la fonction. Il doit se comporter comme target = "_blank" et dans votre < formulaire > :

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

Voici un exemple d'utilisation d'un ensemble de _attributes _ comme indiqué aux liens fournis pour ouvrir une fenêtre d'une taille et d'une position spécifiques avec des parties spécifiques de l'interface utilisateur supprimées:

// 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');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top