简体   繁体   English

从弹出窗口打开完整/常规浏览器窗口

[英]Open complete/ regular browser window from pop-up

In my site I have a pop up window which get opened on page load. 在我的网站上,我有一个弹出窗口,该页面在页面加载时打开。 This pop up contains a link 该弹出窗口包含一个链接

<a href='newpage.html' target='_blank'>click here to go to page</a>

Currently when user clicks on the link, new page either opens in same pop up window or it opens a new pop up window. 当前,当用户单击链接时,新页面会在相同的弹出窗口中打开,或者会打开一个新的弹出窗口。

How can I achieve it so instead of new page opens in a pop-up window, it opens in a regular browser window. 我如何实现它,而不是在弹出窗口中打开新页面,而是在常规浏览器窗口中打开。

Is there any tool and what's the best way to achieve this? 有没有什么工具,什么是实现这一目标的最佳方法?

If you mean have the page open as a new tab instead of a popup window, I believe the default behaviour of window.open with the '_blank' attribute should do this. 如果您是说要以新标签页而不是弹出窗口的形式打开页面,我相信带有'_blank'属性的window.open的默认行为应该可以做到这一点。 Something like this, in regular JS: 在普通的JS中是这样的:

var links = document.querySelectorAll('[target="_blank"]');
Array.prototype.forEach.call(links, function (link) {
  link.addEventListener('click', function (e) {
    e.preventDefault();
    var win = window.open('http://www.example.com', '_blank');
    win.focus();
  });
});

Or in JQuery: 或在JQuery中:

$('[target="_blank"]').click(function(e) {
  e.preventDefault();
  var win = window.open('http://www.google.com', '_blank');
  win.focus();
});

However, it's worth noting that most (if not all) browsers allow users to override that behaviour and force windows to either always open as new tabs or new windows. 但是,值得注意的是,大多数(如果不是全部)浏览器都允许用户覆盖该行为,并强制窗口始终作为新选项卡或新窗口打开。 Just bear that in mind when testing if you're not seeing the expected results. 如果在测试中看不到预期的结果,请记住这一点。 As far as I know, if a user has specified the behaviour, there is no way to override it (and nor should there be, really). 据我所知,如果用户指定了行为,则没有任何方法可以覆盖它(也不应确实存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM