var ConsoleManager = {
onOpen: function () {
try {
window.open("about:blank", target = "_self")
} catch (e) {
var n = document.createElement("button");
n.onclick = function () {
window.open("about:blank", target = "_self")
}, n.click()
}
},
onClose: function () {
alert("Console is closed!!!!!")
},
init: function () {
var e = this,
n = document.createElement("div"),
t = false,
o = false;
Object.defineProperty(n, "id", {
get: function () {
t || (e.onOpen(), t = !0), o = !0
}
}), setInterval(function () {
o = !1,
console.info(n),//console.log/console.info等console.api只有在控制台打开才会执行而打印n即一个div,会调用这个dom对象的获取id的方法,因此达到打开空白页的方法
console.clear(),
!o && t && (e.onClose(), t = !1)
}, 200)
}
};
ConsoleManager.init();
参考:
https://github.com/Netrvin/PageGuard.js
网友评论