是否可以使用自定义函数覆盖 window.location 函数? [英] Is it possible to overwrite window.location function with a custom function?

查看:31
本文介绍了是否可以使用自定义函数覆盖 window.location 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以禁用,或者甚至更好地替换为自定义函数,window.location?

Is it possible to disable, or even better, replace with a custom function, window.location?

这个问题是相关的:禁用javascript中的内置函数(警报)

虽然它对 window.alert 工作得很好,但这对 window.location 不起作用.

While it works quite well for window.alert, this does not work for window.location.

我们希望能够找到一种替换或禁用的方法(替换是理想的,因此我们可以进行 AJAX 日志)window.location...肮脏的广告商有时会使用此方法窃取人们远离我们的网络资产.

We would love to be able to find a way to replace or disable (replace would be ideal, so we can AJAX log) window.location... Dirty advertisers have at times before used this to steal people away from our web properties.

有什么想法吗?

即使只在少数特定浏览器上有效的东西也可以,因为一旦被捕获(通过 AJAX 日志记录),我们就可以相当迅速地采取行动.

Even something that only works on a few specific browsers would be fine as once caught (via AJAX logging) we can act on this fairly quickly.

推荐答案

我不相信你可以重新分配 window.location.来自 MDN:

I don't believe you can reassign window.location. From MDN:

总结

返回一个 Location 对象,它包含有关 URL 的信息文档并提供了方法改变那个网址.您也可以分配到此属性以加载另一个 URL.

Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.

https://developer.mozilla.org/en/DOM/window.location

因为它需要一个像属性这样的值,你如何将对象/函数重新分配"给另一个值?由于财产行为,我认为这是不可能的.

As it takes a value like a property, how would you "reassign" the object/function to another value? I don't think it's possible due to the property behavior.

这篇关于是否可以使用自定义函数覆盖 window.location 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆