6

js 怎样阻止页面中其它 js 的自动跳转并不弹出任何提示?

 1 year ago
source link: https://www.v2ex.com/t/1005033
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

js 怎样阻止页面中其它 js 的自动跳转并不弹出任何提示?

  kisshere · 2 小时 38 分钟前 · 723 次点击
比如 www.a.com 页面中加载了一个文件:b.js ,在页面加载几秒后执行自动跳转到另一个网站 www.b.com 上去,那么怎样在 www.a.com 中引入一个 js ,阻止其该 b.js 执行自动跳转?如果用 beforeunload 还会弹出一个提示,怎样让该 js 静默的阻止 b.js 的跳转?
4 条回复    2024-01-02 11:20:01 +08:00
paledream

paledream      2 小时 33 分钟前

```js
window.onbeforeunload = () => false;
````
这样试试
Melting

Melting      1 小时 42 分钟前

要阻止可以覆盖原来的跳转函数逻辑,比如重写 setTimeout 或者 window.open
ljtfdt

ljtfdt      1 小时 36 分钟前

1 、先看一下 b.js 里面的跳转逻辑,看看是使用那个函数来实现跳转
2 、让 a.js 先于 b.js 加载
3 、在 a.js 中覆盖 b.js 中使用的函数
Liam1997

Liam1997      9 分钟前

如果仅仅是为了完成需求的话,chrome 浏览器打开 network 面板就可以 block 掉指定资源了,也就是你这里所说的 b.js ,这个方案是最无脑、最快的 ?

麻烦点的话,可以用 chrome search 下 b.js 里相关跳转代码(.open 、.href = 'xxx' 这种),然后加断点进行调试,定位到之后就很好办了,用 Charles 等代理工具或者 Chrome 内置的资源覆盖能力每次访问该网站的时候用本地 js override 掉 b.js

</div


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK