开发者

Get the contents of a class inside an iframe, with Greasemonkey

开发者 https://www.devze.com 2023-03-27 08:22 出处:网络
I have a Greasemonkey script which uses jQuery and detects if a \"class\" is present in the document.

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();

});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号