阻止某些网站打开调试就跳转

https://91mjw.com/,我想把视频地址扒出来单独播放,但是一打开调试就跳转。

https://www.cnblogs.com/jinyuu/p/11590343.html

测试页面,原理我还是不懂: 

<html>
<title>打开调试就跳转</title>
<style>
body { margin:0; }
</style>
<body>
<iframe src="https://www.baidu.com" width="99%" height="99%">
</iframe>
<script>
var element = new Image();
Object.defineProperty(element, 'id', { get: function() { window.location.href = "https://91mjw.com/about"; } });
console.log(element);
</script>
</body>
</html>

解决方法:

添加新书签,网址为以下JS:

javascript:window.addEventListener('beforeunload', function (e) { e.preventDefault();e.returnValue = '' });

网页加载完后,点击这个书签注入JS。

原理:通过监听 beforeunload 事件并指定 returnValue,浏览器会在网页跳转前询问是否离开此网页,点击取消即可留在当前页面。这样当我们打开调试时,就可以取消页面跳转了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章