11 javascript google-chrome referer chromium popup-blocker
我想在chrome的新进程/上下文中打开新窗口(我不确定是否可以使用window.open,但下面的示例是可行的)当前如果是常规窗口,您可以查看以下示例并查看是否弹出窗口阻止程序已启用
ar newWin = window.open(url);
if(!newWin || newWin.closed || typeof newWin.closed=='undefined')
{
//POPUP BLOCKED
}
Run Code Online (Sandbox Code Playgroud)
但我想在没有window.open的新进程中打开新窗口,如下所示
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);
Run Code Online (Sandbox Code Playgroud)
与此参考文献一起使用:http: //news.softpedia.com/news/Force-Google-Chrome-to-Open-Links-in-New-Processes-128962.shtml
从帖子打开新上下文中你应该使用:
aTag.setAttribute('rel',"noreferrer");
aTag.setAttribute('target',"_blank");
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但有时新的窗口/标签会被弹出窗口阻止程序阻止,我只是想知道这一点,并在内部通知用户新窗口被阻止,请启用它...我有哪个选项?
我的要求是这样的:
- 在新流程/上下文中打开窗口
- 如果阻止弹出窗口阻止程序通知用户
怎么做?
UPDATE
我需要它,因为当您单击从现有窗口打开新窗口并打开第二个窗口并返回第一个/源窗口并且您想要执行某些操作时会被阻止!
要模拟这个,您可以创建这个简单的文件
<!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>
Run Code Online (Sandbox Code Playgroud)
现在做下面的事情吧
- 运行程序(html文件),打开CNN选项卡
- 检查CNN选项卡并在其上放置断点 (在源选项卡中,您可以找到javascript,将其放在您选择的任何位置),直到它停止(您需要刷新页面,直到您看到调试器停止...
- 现在回到第一个标签是两个按钮是你看到它被阻止,你不能做点击等等...
如何处理打开新选项卡而不阻止第一个/源选项卡?
更新2
有一种模拟弹出窗口阻止程序的方法,如果代码没有发生
aTag.setAttribute( '相对', "noreferrer"); aTag.setAttribute( '目标', "_空白");
在上一个示例中添加以下代码
<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);
})
}
Run Code Online (Sandbox Code Playgroud)
不太确定您是否要确保打开一个新窗口或新进程,所以也许我会回答这两个问题。
如果你的字面意思是你想确保 Chrome 启动一个新进程,那么在 Javascript 中就没有办法做到这一点,甚至你用window.open. 但是,由于 Chrome 正在为每个选项卡打开一个新进程,因此只要您的用户正在使用 Chrome,就可以安全地假设您的消息处于新进程中。另一方面,检查您的用户使用的浏览器是可能的。尽管您的用户可能仍然伪造用户代理(即浏览器),但它对于内部使用来说应该足够了。
有关 Chrome 使用新进程而不是每个选项卡的新线程的更多参考。
如果您想确保用户在新窗口中打开消息,则带有 的选项window.open是唯一的选择。您可以window.open通过添加事件侦听器或简单地使用onclickHTML 中的属性来触发。单独使用 HTML 是没有办法做到的,当你已经找到了使用 javascript 做到这一点的方法时,就没有理由去搜索答案了?
| 归档时间: |
|
| 查看次数: |
1122 次 |
| 最近记录: |