检查弹出窗口阻止程序在打开新选项卡时是否变亮 [英] Check if pop-up blocker is enbled when open new tab

查看:145
本文介绍了检查弹出窗口阻止程序在打开新选项卡时是否变亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  ar newWin = window.open(url) ; 

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

但我想在新进程中打开新窗口,而不需要window.open

  var prod = document.getElementById(myElement); 
var aTag = document.createElement('a');
Tag.setAttribute('href',http://cnn.com);
//这两行完成工作
Tag.setAttribute('rel',noreferrer);
aTag.setAttribute('target',_ blank);
prod.appendChild(aTag);
Tag.click();
prod.removeChild(aTag);

与此引用一起使用:
http://news.softpedia.com/news/Force-Google-Chrome在新的上下文中打开新标签,你应该使用:

/ p>

  aTag.setAttribute('rel',noreferrer); 
aTag.setAttribute('target',_ blank);

当这个工作正常时,有时候新的窗口/标签会被弹出窗口拦截器阻止,I只是想知道这一点,并通知内部用户新窗口被阻止,请启用它...我有哪些选项?



我的要求是
$ b



  1. 在新进程/上下文中打开窗口

  2. 如果弹出窗口阻止程序被阻止通知用户


如何完成? / p>

更新



我需要它,因为当您点击以从现有的窗口,第二个窗口打开,你回到第一个/源窗口,你想做一些它的阻止!



为了模拟这个你可以创建这个简单的文件

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

< br />
< br />
< button onclick =windowOpen('http://cnn.com')>窗口打开本地< /按钮>
< br />
< br />
< button onclick =windowOpen('http://google.com')>样本< / button>

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

< / script>
< / html>

现在请执行以下操作:



  1. 运行程序(html文件),这将打开CNN标签

  2. 检查CNN标签并在其上放置中断点(在源选项卡中,您可以找到javascript,将它放在您选择的任何位置),直到它停止(您需要刷新页面,直到看到调试器停止。

  3. 现在回到第一个标签页,两个按钮就是这样,你看到它被阻止,你不能做任何事情,比如点击等等。


如何在不阻止第一个/源标签的情况下处理新标签?

更新2



有一种方法可以模拟弹出式窗口拦截器,

aTag.setAttribute('rel',noreferrer);
aTag.setAttribute('target',_ blank);

将以下代码添加到前面的e中xample

 < script src =https://cdn.jsdelivr.net/bluebird/3.4.5/bluebird.js >< /脚本> 
< br />
< br />
< button onclick =EnabledPPB('http://cnn.com')>阻止器< /按钮>

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

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

}


解决方案

不确定要打开新窗口或新程序,所以也许我会同时回答。



如果你字面意思是你想确保Chrome开始一个新的进程,在JavaScript中没有办法做到这一点,甚至没有你用 window.open 显示的代码。但是,由于Chrome为每个标签打开了一个新流程,因此只要用户使用Chrome,就可以安全地使用新的流程。另一方面,检查用户正在使用的浏览器是可能的。虽然你的用户可能仍然伪造用户代理(即浏览器),但它应该足够内部使用。



在Chrome浏览器中使用新进程而不是每个选项卡的新线程的更多参考资料



如果您想确保您的用户在新窗口中打开您的消息,那么使用 window.open 是唯一的选择。您可以通过添加事件侦听器来触发 window.open ,或者仅使用HTML中的 onclick 属性。有没有办法单独使用HTML,并且当你已经找到一种方法来使用javascript时,应该没有理由搜索答案?


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

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

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. if the popup blocker is blocked notify the user

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

  1. Run the program (the html file), this open the CNN tab
  2. 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...
  3. 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...

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

UPDATE 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");

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);
        })

}

解决方案

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.

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

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?

这篇关于检查弹出窗口阻止程序在打开新选项卡时是否变亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆