弹出前删除警报框 [英] Remove Alert box before it pops up
问题描述
我正在尝试使用Grease Monkey和jQuery删除外部站点上的警报"框.
I am trying to remove an Alert box on an external site with Grease Monkey and jQuery.
HTML:
<!DOCTYPE html>
<html>
<body>
<script>alert("Remove this Alert box with GreaseMonkey.");</script>
<p>Hello world</p>
</body>
</html>
GreaseMonkey脚本(当前没有jQuery部分):
GreaseMonkey script (currently without the jQuery part):
// ==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)时才触发.
I don't think this can be solved using jQuery since the jQuery code only triggers when the page has loaded and the alert is visible ($(document).ready).
我可以从DOM中删除警报元素吗?
如果出现警报,我可以发送一个按键(13 = Enter)来处理警报吗?
Can I remove the alert-element from the DOM?
Can I send a keypress (13=Enter) to handle the alert if it shows up?
谢谢.
推荐答案
由于Greasemonkey在页面加载后且脚本没有任何事件触发,所以我认为无法实现所需的内容.
Since Greasemonkey is loaded after the page and the script isn't triggered by any event, I think it's impossible to achieve what you are looking for.
这篇关于弹出前删除警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!