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只有在控制臺打開才會執(zhí)行而打印n即一個div,會調用這個dom對象的獲取id的方法,因此達到打開空白頁的方法
console.clear(),
!o && t && (e.onClose(), t = !1)
}, 200)
}
};
ConsoleManager.init();
參考:
https://github.com/Netrvin/PageGuard.js