0

我有一个下拉选择器,我需要更改它,以便 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>

提前致谢

4

1 回答 1

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

_attributes_可以在此处找到 Mozilla的列表或此处的 IE列表。一些可用选项存在一些差异,因此最好查看两个列表。

您还可以将第三个参数从函数调用中移除,它的行为应该类似于target="_blank"您的<form>

// 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');
于 2009-09-16T22:10:14.120 回答