Selector desplegable, cambiar a target = & # 8220; _blank & # 8221;
-
07-07-2019 - |
Pregunta
Tengo un selector desplegable en su lugar y necesito cambiarlo para que el objetivo = " _blank " entonces abre una nueva pestaña.
Aquí está el código actual:
<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>
Gracias de antemano
Solución
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;
}
Se puede encontrar una lista de _attributes_
aquí para Mozilla o aquí para IE . Existen algunas diferencias en algunas de las opciones disponibles, por lo que es mejor revisar ambas listas.
También puede dejar el tercer parámetro fuera de la llamada a la función y debería comportarse como target = " _blank "
en su < form >
:
// behaves as if you submitted <form ... target="_blank">:
window.open(myVal, mySel.form.target);
Aquí hay un ejemplo usando un conjunto de _attributes_
como se documenta en los enlaces provistos para abrir una ventana de un tamaño y posición específicos con partes específicas de la IU suprimidas:
// 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');