我有一个下拉选择器,我需要更改它,以便target =" _blank"所以它打开了一个新标签。

以下是当前代码:

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

提前致谢

有帮助吗?

解决方案

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

_attributes _ 列表可以在这里找到Mozilla 此处为IE 。某些可用选项存在一些差异,因此最好同时查看这两个列表。

您也可以将第三个参数保留在函数调用之外,它的行为应该与&lt; form&gt; 上的 target =&quot; _blank&quot; 相同:

// 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');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top