반응형
JavaScript window.location에 target =“_ blank”를 추가하는 방법은 무엇입니까?
다음은 대상을로 설정합니다 _blank
.
if (key == "smk") {
window.location = "http://www.smkproduction.eu5.org";
target = "_blank";
done = 1;
}
그러나 이것은 작동하지 않는 것 같습니다. 새 탭에서 링크를 시작하려면 어떻게합니까?
내 코드는 다음과 같습니다.
function ToKey() {
var done = 0;
var key = document.tokey.key.value;
key = key.toLowerCase();
if (key == "smk") {
window.location = "http://www.smkproduction.eu5.org";
target = "_blank"
done = 1;
}
if (done == 0) {
alert("Kodi nuk është valid!");
}
}
<form name="tokey">
<table>
<tr>
<td>Type the key</td>
<td>
<input type="text" name="key">
</td>
<td>
</td>
<td>
<input type="button" value="Go" onClick="ToKey()">
</td>
</table>
</form>
window.location
현재 창의 URL을 설정합니다. 새 창을 열려면을 사용해야 window.open
합니다. 이것은 작동합니다.
function ToKey(){
var key = document.tokey.key.value.toLowerCase();
if (key == "smk") {
window.open('http://www.smkproduction.eu5.org', '_blank');
} else {
alert("Kodi nuk është valid!");
}
}
당신의 if (key=="smk")
if (key=="smk") { window.open('http://www.smkproduction.eu5.org','_blank'); }
he creado una función que me allowe obtener esta característica, si alguien tiene alguna sugerencia para mejorarla por favor compartirla, muchas gracias
안녕하세요,이 기능을 얻을 수있는 기능을 만들었습니다. 개선에 대한 제안이 있으시면 공유 해주세요. 감사합니다.
function redirect_blank(url) {
var a = document.createElement('a');
a.target="_blank";
a.href=url;
a.click();
}
var linkGo = function(item) {
$(item).on('click', function() {
var _$this = $(this);
var _urlBlank = _$this.attr("data-link");
var _urlTemp = _$this.attr("data-url");
if (_urlBlank === "_blank") {
window.open(_urlTemp, '_blank');
} else {
// cross-origin
location.href = _urlTemp;
}
});
};
linkGo(".button__main[data-link]");
.button{cursor:pointer;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="button button__main" data-link="" data-url="https://stackoverflow.com/">go stackoverflow</span>
참고 URL : https://stackoverflow.com/questions/18476373/how-to-add-target-blank-to-javascript-window-location
반응형
'program story' 카테고리의 다른 글
자동 레이아웃을 사용하여 동적 테이블 뷰 섹션 헤더 높이를 얻을 수 있습니까? (0) | 2020.08.21 |
---|---|
Android 캔버스 그리기 직사각형 (0) | 2020.08.21 |
UIView와 CALayer의 차이점은 무엇입니까? (0) | 2020.08.21 |
CSS : img : hover에서 이미지 src 변경 (0) | 2020.08.21 |
오류 : 요청 헤더 필드 Content-Type은 Access-Control-Allow-Headers에서 허용되지 않습니다. (0) | 2020.08.21 |