javascript - mootools。无法在 iframe 中获取 DOM 元素

标签 javascript iframe mootools

我有一个基于 SocialEngine 4 的站点,它使用 moo-tools-1.2.5。 有一个带有一些 js 的 iframe 在弹出窗口中打开(带有内置的 Smoothbox 插件)。 而且我无法通过调用 $$() 从 JS 中获取此 iframe 的 DOM 元素,我需要使用这样的 kludge:

var context = (window.frames[0]) ? window.frames[0] : window;
context.$('user_email').set('value', context.$('1_1_30').get('value'));

这很奇怪,我猜这是意外行为,因为标准 SocialEngine 模块中的 JS 在 iframe 中也不起作用。

最佳答案

这是因为在 1.2.5 中,$$this.document.getElements 的别名。

我建议您使用 IFrame wrapper class来自 mootools-core,它可以扩展 iframe,使它们变得 mootoolsy,然后您可以执行以下操作:

var context = this.document, // window
    iframe = document.getElement("iframe")

// if iframe found, change context to its contentDocument
iframe && (context = new IFrame("foo").contentDocument)

// wrapper.
!function() {
    console.log(this.getElements("div"))
}.call(context)

关于javascript - mootools。无法在 iframe 中获取 DOM 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10136468/

相关文章:

javascript - 在javascript中循环遍历python-dictionary-turned-into-json

javascript - FireFox 捕获自动完成输入更改事件

javascript - rails + Chartkick : How to change the date format of the tooltip?

javascript - 如果其列表 li 中的任何一个具有事件类,则展开子菜单列表 OL

css - 定位 iframe

css - 如何使用 iframe 将 css 应用于外部加载网页。是否可以?

Facebook Like WordPress 中的 500 错误

javascript - 根据页面滚动更改div位置

javascript - 使用 moo 工具的 Fx.Slide 操纵许多滑动对象的最佳方式

javascript - Keyup 记录 key-ups 的总数