같은 창과 같은 탭에서 URL 열기
같은 창과 링크가있는 페이지가 포함 된 동일한 탭에서 링크를 열고 싶습니다.
을 사용하여 링크를 열려고 window.open
하면 동일한 창의 동일한 탭이 아닌 새 탭에서 열립니다.
이름 속성을 사용해야합니다.
window.open("https://www.youraddress.com","_self")
편집 : URL 앞에 프로토콜이 붙어야합니다. 그것이 없으면 상대 URL을 열려고합니다. Chrome 59, Firefox 54 및 IE 11에서 테스트되었습니다.
이것을 사용하십시오 :
location.href = "http://example.com";
링크가 동일한 탭에서 열리도록하려면 window.location.replace()
아래 예를 참조하십시오.
window.location.replace("http://www.w3schools.com");
출처 : http://www.w3schools.com/jsref/met_loc_replace.asp
URL을 지정하지 않고 동일한 페이지로 이동할 수 있습니다.
window.open('?','_self');
"frame"안에 페이지가 있으면 "Window.open ( 'logout.aspx', '_ self')"
동일한 프레임 내에서 리디렉션됩니다. 따라서
"Window.open('logout.aspx','_top')"
새로운 요청으로 페이지를로드 할 수 있습니다.
가장 두드러진 자바 스크립트 기능 중 하나는 onclick 핸들러를 즉시 실행하는 것입니다. 내가 사용하는 것보다 더 신뢰할 수있는 메커니즘을 다음 발견 location.href=''
하거나 location.reload()
또는 window.open
:
// this function can fire onclick handler for any DOM-Element
function fireClickEvent(element) {
var evt = new window.MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
element.dispatchEvent(evt);
}
// this function will setup a virtual anchor element
// and fire click handler to open new URL in the same room
// it works better than location.href=something or location.reload()
function openNewURLInTheSameWindow(targetURL) {
var a = document.createElement('a');
a.href = targetURL;
fireClickEvent(a);
}
위의 코드는 새 탭 / 창을 열고 모든 팝업 차단기를 무시하는데도 도움이됩니다 !!! 예 :
function openNewTabOrNewWindow(targetURL) {
var a = document.createElement('a');
a.href = targetURL;
a.target = '_blank'; // now it will open new tab/window and bypass any popup blocker!
fireClickEvent(a);
}
링크 클릭으로 다른 URL 열기
window.location.href = "http://example.com";
사용해야 window.open
합니까? 사용하는 것은 window.location="http://example.com"
어떻습니까?
window.open(url, wndname, params)
여기에는 세 가지 주장이 있습니다. 같은 창에서 열지 않으려면 다른 wndname을 설정하십시오. 같은 :
window.open(url1, "name1", params); // this open one window or tab
window.open(url1, "name2", params); // though url is same, but it'll open in another window(tab).
에 대한 자세한 내용은 다음과 같습니다. window.open()
신뢰할 수 있습니다.
https://developer.mozilla.org/en/DOM/window.open
시도해보십시오 ~~
html 5에서는 history API를 사용할 수 있습니다 .
history.pushState({
prevUrl: window.location.href
}, 'Next page', 'http://localhost/x/next_page');
history.go();
그런 다음 다음 페이지에서 상태 객체에 액세스 할 수 있습니다.
let url = history.state.prevUrl;
if (url) {
console.log('user come from: '+ url)
}
꽤 쉽습니다. 다음과 같이 첫 번째 창 열기window.open(url, <tabNmae>)
예: window.open("abc.com",'myTab')
그리고 다음 모든 window.open를 들어, 사용하는 같은 탭 이름 대신 _self
, _parent
등
정확히 이렇게 window.open("www.youraddress.com","_self")
Just Try in button.
<button onclick="location.reload();location.href='url_name'"
id="myButton" class="btn request-callback" >Explore More</button>
Using href
<a href="#" class="know_how" onclick="location.reload();location.href='url_name'">Know More</a>
MDN의 심판이 말했듯이 new window
/ 의 이름을 지정하면 tab
됩니다.
https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Syntax
<div style="margin: 5px;">
<a
:href="url"
@click="autoOpenAlink"
target="_blank"
>
{{url}}
</a>
</div>
부
autoOpenAlink(e) {
e.preventDefault();
let url = this.url;
window.open(url, "iframe testing page");
},
참고 URL : https://stackoverflow.com/questions/8454510/open-url-in-same-window-and-in-same-tab
'Programing' 카테고리의 다른 글
π의 가치를 얻는 가장 빠른 방법은 무엇입니까? (0) | 2020.03.11 |
---|---|
Eclipse에서 빵 부스러기를 비활성화하는 방법 (0) | 2020.03.11 |
패키지 이름과 일치하는 클라이언트를 찾을 수 없습니다 (Google Analytics)-여러 productFlavors & buildTypes (0) | 2020.03.11 |
Vim에서 세로 분할 창 크기를 늘리는 방법 (0) | 2020.03.11 |
iPhone의 탐색 모음에서 '뒤로'버튼을 숨기는 방법? (0) | 2020.03.11 |