我想要删除与Grease Monkey和jQuery的外部网站上的警报框。弹出之前删除警报框
HTML:
<!DOCTYPE html>
<html>
<body>
<script>alert("Remove this Alert box with GreaseMonkey.");</script>
<p>Hello world</p>
</body>
</html>
的GreaseMonkey脚本(目前没有jQuery的一部分):
// ==UserScript==
// @name Remove Alert box
// @include http://www.example.com/alert_remove/
// ==/UserScript==
var node = document.getElementsByTagName('alert');
node.parentNode.removeChild(node);
if(window.alert) {
alert("ALERT DETECTED"); // No response.
}
我不认为这是可以使用jQuery因为jQuery代码仅触发时,页面被解决已加载并且警报可见($(document).ready)。
我可以从DOM中删除警报元素吗?
如果出现警报,我可以发送按键(13 = Enter)来处理警报吗?
谢谢。
有趣的解决方案。弹出Alert时只需发送按键(Enter)怎么样?它可以使用AutoHotkey完成,但使用JavaScript? – 2010-03-04 05:11:07
不,很遗憾没有按键发送机制。您可以检测按键,并处理它们,你可以触发你定义的按键处理程序,但没有办法模仿的网页之外的按键事件(包括在警报窗口,在浏览器等其他领域) – Ricket 2010-03-04 05:42:45