簡體   English   中英

下拉選擇器,更改為target =“ _ blank”

[英]Dropdown selector, change to target=“_blank”

我有一個下拉選擇器,需要對其進行更改,以便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;
}

可以在此處為MozillaIE找到_attributes_的列表。 在某些可用選項中存在一些差異,因此最好查看兩個列表。

您還可以將第三個參數保留在函數調用之外,它的行為應類似於<form>上的target="_blank"

// 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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM