我有一个基于 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/