停止脚本更改document.location.href
Stopping script from changing document.location.href?
我刚刚浏览过的一个网站(cheezburger.com)显然有漏洞,因为有人在消息中注入了<script>document.location.href="http://net-cheezburger.cu.cc/"</script>
之类的行。Firefox将自己重定向到那里,X-Frame-Options停止帧,导致空屏幕。
除了在cheezburger站点的document.location.href中添加一个CAPS策略之外,还有其他方法可以阻止脚本在Firefox中工作吗?这也阻碍了合法的变革。现在我只是警告Greasemonkey脚本在错误的地方,所以如果他们尝试其他恶意脚本,我可以立即知道发生了什么。
我只是想临时修复,直到网站本身修复。
我想知道是否有办法以编程方式拦截该脚本或重定向。如果我理解正确,你不能改变内联脚本与Greasemonkey,但有其他选择吗?
由于您使用的是firefox(一种现代浏览器),您可以使用Object.freeze
将location
对象变为只读:
Object.freeze(document.location);
document.location.href = "http://google.com";
// No navigation happens
console.log(document.location.href);
// => "http://stackoverflow.com/questions/22290948/stopping-script-from-changeing-document-location-href"
相关文章:
- 对象.在document.location上进行观测
- PhoneGap如何在更改window.location/document.location后保持Javascript的
- Javascript document.location.reload不起作用
- 了解document.location.htm何时完成
- 通过document.location以javascript中的字符串形式传递文件路径
- 使用document.location=file_url.mp3触发从JS下载-不正确
- document.location 在后续代码之后颁布
- Routing.navigate vs document.location.hash
- Javascript button and document.location
- Javascript 页面呈现为文本,而不是执行 document.location
- 保证在任何 document.location 更改之前执行 Javascript AJAX
- 如何使用 PHP 获取 document.location.href 的值
- JavaScript document.location.href 似乎期待 HTML
- 在 JavaScript 中为 document.location 创建钩子
- Javascript - 我可以拦截对 document.location.href 的调用吗?
- childwindow.document.location.reload() 不起作用
- document.location 在尝试下载文件时修改 WebApi 路由
- 动态渲染单击document.location
- document.location.htm在IE中不起作用
- .js代码中给出的document.location()函数在Internet Explorer中工作正常,但在Fire