使用Greasemonkey在iframe中获取类的内容 [英] Get the contents of a class inside an iframe, with Greasemonkey

查看:128
本文介绍了使用Greasemonkey在iframe中获取类的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Greasemonkey脚本,它使用jQuery并检测文档中是否存在类。

I have a Greasemonkey script which uses jQuery and detects if a "class" is present in the document.

var damageMessage = $(".mw_error").text();

当文档加载并且 damageMes​​sage 拥有一个文本字符串。

This works fine when the document loads and damageMessage holds a text string.

问题是class .mw_error 在iframe内部你点击里面的新链接,iframe内容加载没有页面刷新,但类的内容确实改变,我想得到新的内容或文本字符串。

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.

我猜这是因为文档没有重新加载Greasemonkey脚本不会再次加载并尝试查找更新的类内容。不知何故,我需要获得该课程的新内容。

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

推荐答案

在load方法上使用iframe并获取所需元素的文本。这将确保每次刷新iframe时都会获得在iframe中加载的新文本。

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

});

这篇关于使用Greasemonkey在iframe中获取类的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆