드롭다운 선택기, target="_blank"로 변경
-
07-07-2019 - |
문제
드롭다운 선택기가 있고 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의 경우 여기.사용 가능한 일부 옵션에는 몇 가지 차이점이 있으므로 두 목록을 모두 검토하는 것이 가장 좋습니다.
함수 호출에서 세 번째 매개변수를 생략할 수도 있으며 이는 다음과 같이 동작해야 합니다. 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');
제휴하지 않습니다 StackOverflow