【问题标题】:I can't gather data from iframe via chrome extension我无法通过 chrome 扩展从 iframe 收集数据
【发布时间】:2011-12-25 16:32:12
【问题描述】:

我正在尝试制作 5 星评级扩展程序,使 5 星出现在某个网页上,并收集有关有多少用户评级和平均评级的数据。我制作了一个 .php 页面,其中包含两个名为“total”和“star”的 div 标签 - 包含总评分和平均评分,我在其中创建了一个打开该页面的 iFrame。

当我试图抓取数据时,使用

 totalrating = $('#getrating').contents().find('#total').html();

(getrating = iframe,total = div 标签和总评分)

它返回空值。我做错了什么吗?获得 5 颗星的页面与我的网站不同,所以我认为除了使用 iFrame 之外别无他法。

谢谢,亚历克斯。

【问题讨论】:

标签: javascript google-chrome google-chrome-extension


【解决方案1】:

'contents()'函数只有在iframe存在于同一个域的情况下才能获取内容。

也许这有帮助:

http://pipwerks.com/2008/11/30/iframes-and-cross-domain-security-part-2/

【讨论】:

    【解决方案2】:

    也许这行得通:

    totalrating = $(document.getElementById('getrating').contentDocument).find('#total').html();
    

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 1970-01-01
      • 2014-12-18
      • 2022-11-10
      • 2014-10-01
      • 2021-07-12
      • 2012-10-27
      • 2018-07-25
      • 1970-01-01
      相关资源
      最近更新 更多