Wednesday, March 3, 2010

Programmer - Remove Alert box before it pops up

Programmer Question

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 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.
}


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).



Can I remove the alert-element from the DOM?

Can I send a keypress (13=Enter) to handle the alert if it shows up?



Thanks.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails