脚本调用弹出新窗口被拦截情况总结 - acelan86/whatthefuck GitHub Wiki
var evt = ['scroll', 'click', 'mouseover', 'mouseout', 'mousemove'];
window.cblist = {};
for (var i = 0, len = evt.length; i < len; i++) {
window.cblist[evt[i]] = (function (type) {
return function () {
sinaadToolkit.event.un(type === 'scroll' ? window : document.body, type, window.cblist[type]);
alert(type);
window.open('http://sina.com.cn#' + type, type, 'width=800,height=300');
};
})(evt[i]);
sinaadToolkit.event.on(evt[i] === 'scroll' ? window : document.body, evt[i], window.cblist[evt[i]]);
}
function openByForm() {
var type = 'open by form';
alert(type);
var form = document.createElement('form');
document.body.appendChild(form);
form.action = 'http://sina.com.cn#' + type;
form.target = '_blank';
form.submit();
};
openByForm();
浏览器 | click | scroll | mousemove | mouseout | mouseover | form.submit |
---|---|---|---|---|---|---|
Mac chrome | y | n | n | n | n | n |
Mac firefox | y | n | n | n | n | n |
win chrome | y | n | n | n | n | n |
win firefox | y | n | n | n | n | n |
360 极速模式 | y | n | n | n | n | n |
360 兼容模式 | y | n | n | n | n | n |
IE6 | y | n | n | n | n | n |
IE7 | y | n | n | n | n | n |
IE8 | y | n | n | n | n | n |
IE9 | y | n | n | n | n | n |
IE10 | y | n | n | n | n | n |
IE11 | y | n | n | n | n | n |
心好痛,用户不一定想click啊。。
换个国新给的思路,测试下被拦截有什么特征, 如果能得到这个特征,就退而求其次,在被拦截的时候使用click + win.open来弹出背投
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title> 测试拦截是的窗口句柄 </title>
</head>
<body>
<script>
var win = null;
try {
win = window.open('http://sina.com.cn');
} catch (e) {
//拦截的时候会报错么?
alert('throw error:' + e.message);
}
//拦截的时候能得到win么?
alert(win);
</script>
</body>
</html>
浏览器 | 窗口句柄 | 拦截是否报错 |
---|---|---|
Mac chrome | undefined | no |
Mac firefox | null | no |
win chrome | undefined | no |
win firefox | null | no |
360 极速模式 | undefined | no |
360 兼容模式 | null | no |
IE6 | null | no |
IE7 | null | no |
IE8 | null | no |
IE9 | null | no |
IE10 | null | no |
IE11 | null | no |
看来,被拦截的时候窗口句柄不是undefined就是null, 可以通过这个判断是否窗口被拦截,好事:)
这样的话,背投广告可以退一步变成:
var _pop = window.open('http://sina.com.cn');
if (!_pop) {
var popWin = function _popWin() {
sinaadToolkit.event.un(document.body, 'click', _popWin);
var _pop = window.open('http://sina.com.cn');
_pop.blur();
_pop.opener.focus();
};
//窗口被拦截,用户点击的时候再次默默弹窗 - -|||
sinaadToolkit.event.on(document.body, 'click', popWin);
}
但是这样如果用户好奇把拦截的窗口打开,就会产生两次曝光,因此,代码要改成这样,在第一次pop的时候先打开一个空白窗口,这样拦截的也就是空白窗口,如果没有被拦截,就使用窗口句柄进行url设置,然后代码变成这样:
var _pop = window.open('about:blank');
if (!_pop) {
var popWin = function _popWin() {
sinaadToolkit.event.un(document.body, 'click', _popWin);
var _pop = window.open('http://sina.com.cn');
_pop.blur();
_pop.opener.focus();
};
//窗口被拦截,用户点击的时候再次默默弹窗 - -|||
sinaadToolkit.event.on(document.body, 'click', popWin);
} else {
_pop.blur();
_pop.opener.focus();
_pop.location = 'http://sina.com.cn';
}
有点代码重复和小细节,再说,大体就是这样了,好像其他无解,另,今天zhouyi找到一个说明,谢谢zhouyi:http://technet.microsoft.com/zh-cn/security/bulletin/ms05-013?altTemplate=SecurityBulletinPF(DHTML 编辑组件 ActiveX 控件跨域漏洞 (CAN-2004-1319)),是windows的一个漏洞,在部分系统及特定情况下可以执行弹出窗口,太高深,也不适合所有浏览器和平台,反而会增加代码复杂度,不利于维护,早晚要跪,因此考虑不采用这种方法
附上利用这个漏洞弹窗的代码 http://good.ta80.com/js/cp.js(来自某网站,绝对不是黄色的网站-。-|||)
focus(), blur() 在chrome,firefox中不起作用,继续求破