我正在解雇Window.open();命令.这将在另一个选项卡中打开链接页面.我想要的是当我点击链接时,链接将在新窗口中打开但应该在同一页面上.
那可能吗 ?
目前我正在使用这样的.
function AddToDatabase(url) {
window.open(url, "_blank");
}
Run Code Online (Sandbox Code Playgroud)
Uma*_*eem 12
使用_self而不是_blank.
window.open(url, "_self");
Run Code Online (Sandbox Code Playgroud)
有关详细信息.请参阅此链接
我知道这个问题非常古老,但它完美地描述了我需要回答的问题,并且我能够提出一个不错的解决方案,所以我想我应该将其发布在这里。这是一个有趣的解决方法。
本质上,您设置一个超时来延迟将当前页面转发到新的 url,然后在新选项卡中打开当前的 url。所以:
function open_hidden_tab(new_url) {
var thisTimeout= setTimeout(function() {
window.location.href= new_url;
}, 500);
var newWindow= window.open(window.location.href);
if(!newWindow) {
clearTimeout(thisTimeout);
alert('Please allow pop-ups on this site!');
}
}
open_hidden_tab('https://google.com');
Run Code Online (Sandbox Code Playgroud)
显然,您应该在站点上显示某种错误消息,而不是使用烦人的警报功能,但它适用于本示例的目的。
希望这对某人有帮助!