我想在相同的窗口和相同的选项卡中打开一个链接,其中包含有链接的页面。
当我试图打开一个链接使用窗口。打开,然后在新选项卡中打开——而不是在同一窗口的同一选项卡中。
我想在相同的窗口和相同的选项卡中打开一个链接,其中包含有链接的页面。
当我试图打开一个链接使用窗口。打开,然后在新选项卡中打开——而不是在同一窗口的同一选项卡中。
当前回答
就像这样 _self window.open (" www.youraddress.com ", " ")
其他回答
使用_self打开当前标签页中的url
const autoOpenAlink = (url = ' ') => { 窗口。打开(url,“在同一个标签页中打开测试页面”); } <一个 href = " https://cdn.xgqfrms.xyz/index.html " 目标= " _self” onclick = " autoOpenAlink(“https://cdn.xgqfrms.xyz/index.html”)" > 在当前标签页中使用' _self '打开url < / >
在新标签页中使用_blank打开url
const autoOpenAlink = (url = ``) => { window.open(url, "open testing page in a new tab page"); } // ❌ The error is caused by a `StackOverflow` limitation // js:18 Blocked opening 'https://cdn.xgqfrms.xyz/index.html' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set. <a href="https://cdn.xgqfrms.xyz/index.html" target="_blank" onclick="autoOpenAlink('https://cdn.xgqfrms.xyz/index.html')"> open url in a new tab page using `_blank` </a>
refs
根据MDN的文档,你只需要给新窗口/标签一个名字。
https://developer.mozilla.org/en-US/docs/Web/API/Window/open#Syntax
用这个:
location.href = "http://example.com";
你需要使用name属性:
window.open("https://www.youraddress.com","_self")
编辑:Url前应加上协议。没有它尝试打开相对url。在Chrome 59, Firefox 54和IE 11中测试。
你可以这样做
window.close();
window.open("index.html");
它在我的网站上很成功。
如果你有你的页面在“框架”那么 “Window.open(“logout.aspx”、“_self”)”
将被重定向到同一帧内。所以通过使用
"Window.open('logout.aspx','_top')"
我们可以加载页面作为新的请求。