Get the contents of a class inside an iframe, with Greasemonkey
I have a Greasemonkey script which uses jQuery and detects if a "class" is present in the document.
var damageMessage = $(".mw_error").text();
This works fine when the document loads and damageMessage
holds a text string.
The problem is that the "class" .mw_error
is inside an iframe 开发者_运维知识库and when you click a new link inside, the iframe content loads without a page refresh but the contents of "class" do change and I want to get the new contents or text string.
I’m guessing it’s because the document doesn’t reload that the Greasemonkey script doesn’t load again and try and find the updated class contents. Somehow I need to get the new contents of the class.
Any help on this would be much appreciated :)
Use the iframe on load method and get the text of the required element like this. This will ensure that every time iframe is refreshed you will get the new text that is loaded inside iframe.
$("iframe").load(function(){
var damageMessage = $(this).contents().find(".mw_error").text();
});
精彩评论