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

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

问题描述

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



这个问题是相关的:禁用JavaScript中的内置函数(alert )



尽管它对 window.alert 非常有效,但这对于 window.location



我们希望能够找到替代或禁用的方法(替换将是理想的,所以我们可以使用AJAX日志) window.location ...肮脏的广告客户有时会用它来窃取人们远离我们的网络媒体资源。



任何想法?



即使只能在少数特定浏览器上工作的东西也可以,因为一旦被捕获(通过AJAX日志记录),我们就可以采取行动这很快。

解决方案

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


摘要

返回一个Location对象,其中
包含关于文档
的URL的信息,并提供
更改该URL的方法。 您也可以为此属性分配
来加载另一个URL

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



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


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

This question is related: Disable a built-in function in javascript (alert)

While it works quite well for window.alert, this does not work for 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.

Any ideas?

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.

解决方案

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

Summary

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天全站免登陆