【问题标题】:iframe undefined in Greasemonkey script在 Greasemonkey 脚本中未定义 iframe
【发布时间】:2009-08-27 20:25:44
【问题描述】:

我创建了一个在 firebug 编辑器中运行良好的 Greasemonkey 脚本,删除了 Greasemonkey 的细节,但当我尝试将其打包为用户脚本时却没有。 Firefox 错误控制台报告我尝试使用的 iframe 未定义。

我已将用户脚本缩减到应将 iframe html 打印到 firebug 控制台的最小情况,并且在 firebug 编辑器中运行时会这样做,但不能作为用户脚本工作:

// ==UserScript==
// @name          Movies
// @include       http://*.princecharlescinema.com/*
// @include       http://princecharlescinema.com/*
// ==/UserScript==

// stop script loading multiple times
if (top !=self) return;

var iframeHTML = window.frames['iframe2'].document.documentElement.innerHTML;
unsafeWindow.console.log(iframeHTML);

An example page the script is intended for

如果有用的话,完整脚本的要点是我从这个 iframe 中收集所有 td 标签,从中获取一些信息,然后将一些新的 html 插入到一些相同的 td 标签中。

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript iframe greasemonkey


    【解决方案1】:

    也许你需要等待 DOMFrameContentLoaded

    【讨论】:

    • 我尝试使用长计时器,但问题不在于 iframe 中的某些内容尚未准备好,而是 Greasemonkey 的行为就像实际的 iframe 标签本身不存在一样。
    • 测试一个长计时器并通过它的数组位置 [2] 来识别帧,而不是它的 name 属性让它工作。 DOMFrameContentLoaded 是比 setTimeOut 更好的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 2011-12-06
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多