I have a Greasemonkey script which uses jQuery and detects if a "class" is present in the document.
var damageMessage = $(".mw_error").text();
Thanks to ShankarSangoli he or she gave me the solution to finding the class when the iframe loads with.
$("iframe").load(function(){
var damageMessage = $(this).contents().find(".mw_error").text();
});
The problem I have now is that some of the links in the iframe load content via ajax so the iframe doesn't refresh and I cant get the new value for the class "mw_error". It was suggested that I use a ajax success callback but I'm unsure how to do this.
Any help on this would be much appreciated :)
You can listen for ajax calls, but that gets overly complicated, depending on the target pages. The most robust way to get ajax-ified content on a wild page is to poll for it, like so:
Beware that Greasemonkey can also run on iFrames, so you may not need to do anything other than know if you're in an iFrame, depending upon the script's purpose.
Conversely, you can get unexpected results if the GM script(s) fire on the iFrame URL when you haven't planned on it.
For example, suppose you had this page at URL_A:
And the GM script's
// @include
directive(s) covered both urls (// @include URL_*
, etc.).Then if the script just had
alert ('Script start.');
, you would see 2 alerts upon loading the page.