当打开新选项卡时,检查弹出窗口阻止器是否已被写入

时间:2021-01-24 07:14:07

I want to open new window in new process/context in chrome, (Im not sure if it possible with window.open but with the following example its working ) currently if it was regular window you can check with the following example and to see if the pop-up blocker is enabled

我想在chrome的新进程/上下文中打开新的窗口(我不确定是否可以用窗口)。打开,但使用以下示例它的工作)当前如果它是常规窗口,您可以使用以下示例检查是否启用了弹出窗口拦截器

ar newWin = window.open(url);             

if(!newWin || newWin.closed || typeof newWin.closed=='undefined') 
{ 
     //POPUP BLOCKED
}

but I want to open the new window in new process without window.open like following

但我想在没有窗户的新工艺中打开新窗口。像下面

var prod = document.getElementById("myElement"); 
var aTag = document.createElement('a');
aTag.setAttribute('href',"http://cnn.com");
//THIS TWO LINES do the job
aTag.setAttribute('rel',"noreferrer");
aTag.setAttribute('target',"_blank");
prod.appendChild(aTag);
aTag.click();
prod.removeChild(aTag);

used with this reference: http://news.softpedia.com/news/Force-Google-Chrome-to-Open-Links-in-New-Processes-128962.shtml

使用此引用:http://news.softpedia.com/news/force - google - chrome -to- open -in- new - process -128962.shtml。

from the post to open new tab in new context you should use:

从发布到在新上下文中打开新选项卡,您应该使用:

  aTag.setAttribute('rel',"noreferrer");
  aTag.setAttribute('target',"_blank");

While this is working, sometimes the new window/tab is blocked with the pop-up blocker,I just want to know this and inform the user internally that the new window is blocked and please enable it ...which option do I have?

当它工作的时候,有时新的窗口/选项卡会被弹出窗口阻止,我只是想知道这一点,并在内部通知用户新窗口被阻止了,请启用它……我有什么选择?

My requirements are this:

我的要求是:

  1. Open window in new process/context
  2. 在新进程/上下文中打开窗口
  3. if the popup blocker is blocked notify the user
  4. 如果弹出窗口阻止程序被阻塞,通知用户

How it can be done ?

如何才能做到呢?

UPDATE

更新

I need it since when you click to open new window from existing window and the second window is opened and you return to the first/source window and you want to do something it's blocked!

我需要它,因为当你从现有窗口点击打开新窗口,第二个窗口被打开,你返回到第一个/源窗口,你想做什么,它被屏蔽了!

To simulate this you can create this simple file

要模拟这个,可以创建这个简单的文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>BlockTAB</title>
</head>

<br/>
<br/>
<button onclick="windowOpen('http://cnn.com')">window open native</button>
<br/>
<br/>
<button onclick="windowOpen('http://google.com')">sample</button>

<script>
    function windowOpen(url){
        window.open(url);
    }

</script>
</html>

Now do the folloiwng

现在做folloiwng

  1. Run the program (the html file), this open the CNN tab
  2. 运行程序(html文件),打开CNN选项卡
  3. inspect the CNN tab and put break point on it (in the source tab you can find the javascript, put it in any place you choose),until it stops(you need to refresh the page until you see the debugger stops...
  4. 检查CNN选项卡并在其上放置断点(在source选项卡中可以找到javascript,将其放置在任意位置),直到它停止(您需要刷新页面,直到看到调试器停止……
  5. Now go back to the first tab were the two buttons is and you see that it is blocked, you cannot do anything like click and etc...
  6. 现在回到第一个选项卡,两个按钮是,你看到它被屏蔽了,你不能做任何事情,比如点击等等……

How to handle open the new tab without blocking the first/source tab?

如何在不阻塞第一个/源选项卡的情况下打开新选项卡?

UPDATE 2

更新2

There is a way to simulate the pop-up blocker if it's not happen with the code with

有一种方法可以模拟弹出窗口阻止器,如果在代码中没有出现的话

aTag.setAttribute('rel',"noreferrer"); aTag.setAttribute('target',"_blank");

aTag.setAttribute(“rel”、“noreferrer”);aTag.setAttribute(“目标”,“平等”);

add this following code the previous example

在前面的示例中添加以下代码

<script src="https://cdn.jsdelivr.net/bluebird/3.4.5/bluebird.js"></script>
<br/>
<br/>
<button onclick="EnabledPPB('http://cnn.com')">Blocker</button>

function delayFN(url) {
    Promise.delay(500)
        .then(function() {
            var newWin = window.open(url);
        })
}

function EnabledPPB(url) {
    Promise.delay(100)
        .then(function() {
            delayFN(url);
        })

}

1 个解决方案

#1


3  

Not very sure do you want to make sure to open a new window or new process, so maybe I will answer both.

你不太确定要不要打开一个新窗口或新进程,所以我可能会同时回答这两个问题。

If you literally means you want to make sure Chrome starts a new process, there is no way to do that in Javascript, not even the code you shown with window.open. However, as Chrome is opening a new process for every tab, it is safe to assume your message is in a new process as long as your user is using Chrome. Checking what browser your user is using, on the other hand, is possible. Although your user may still fake the user agent (i.e. the browser), it should be quite enough for internal use.

如果你真的想要确保Chrome启动一个新进程,在Javascript中是无法做到的,即使是windows .open显示的代码也不行。但是,由于Chrome为每个标签打开了一个新进程,所以可以放心地假设,只要用户使用Chrome,您的消息就处于一个新进程中。另一方面,检查用户使用的浏览器是可能的。尽管您的用户可能仍然伪造用户代理(即浏览器),但它应该足以供内部使用。

More reference on Chrome using new process instead of new thread for each tab.

更多关于Chrome的参考使用新进程,而不是每个标签的新线程。

If you want to make sure your user is opening your message in a new window, the one with window.open is the only option. You may trigger window.open by adding event listener or simply use the onclick attribute in HTML. There is no way to do with HTML alone, and there should be no reason to search for answer when you have already found a way to do that with javascript?

如果您想确保您的用户正在一个新的窗口中打开您的消息,这个窗口是有窗口的。开放是唯一的选择。你可能会触发窗口。通过添加事件监听器或在HTML中使用onclick属性打开。没有办法只使用HTML,而且当您已经找到了使用javascript实现这一点的方法时,也不应该搜索答案。

#1


3  

Not very sure do you want to make sure to open a new window or new process, so maybe I will answer both.

你不太确定要不要打开一个新窗口或新进程,所以我可能会同时回答这两个问题。

If you literally means you want to make sure Chrome starts a new process, there is no way to do that in Javascript, not even the code you shown with window.open. However, as Chrome is opening a new process for every tab, it is safe to assume your message is in a new process as long as your user is using Chrome. Checking what browser your user is using, on the other hand, is possible. Although your user may still fake the user agent (i.e. the browser), it should be quite enough for internal use.

如果你真的想要确保Chrome启动一个新进程,在Javascript中是无法做到的,即使是windows .open显示的代码也不行。但是,由于Chrome为每个标签打开了一个新进程,所以可以放心地假设,只要用户使用Chrome,您的消息就处于一个新进程中。另一方面,检查用户使用的浏览器是可能的。尽管您的用户可能仍然伪造用户代理(即浏览器),但它应该足以供内部使用。

More reference on Chrome using new process instead of new thread for each tab.

更多关于Chrome的参考使用新进程,而不是每个标签的新线程。

If you want to make sure your user is opening your message in a new window, the one with window.open is the only option. You may trigger window.open by adding event listener or simply use the onclick attribute in HTML. There is no way to do with HTML alone, and there should be no reason to search for answer when you have already found a way to do that with javascript?

如果您想确保您的用户正在一个新的窗口中打开您的消息,这个窗口是有窗口的。开放是唯一的选择。你可能会触发窗口。通过添加事件监听器或在HTML中使用onclick属性打开。没有办法只使用HTML,而且当您已经找到了使用javascript实现这一点的方法时,也不应该搜索答案。