在用户重定向之前,知道在“location.href”中写入的URL

时间:2016-12-06 06:32:34

标签: javascript redirect

有没有办法将 location.href 写入的网址添加到 window.onbeforeunload 函数中?

我想在我的网站中加入一些第三方js。其中一些可能在其中包含重定向代码:

location.href="http://example.com";

因此,当用户尝试打开我的网站时,它会导致重定向到他们的网站。所以我只是想阻止它。我可以使用:

window.onbeforeunload = function () {
    // Here I want to get the URL where user is going to be redirect
    // If that URL is a 3rd party website, I will return false 
    return false;
}

据我所知,这是不可能的。

任何帮助都将不胜感激。

PS:我已经检查了这个:How can i get the destination url in javascript onbeforeunload event?

所以简单地说,我只是想阻止这种自动化的第三方重定向。是否有可用的代码/工具/脚本

谢谢, Parth vora

0 个答案:

没有答案