Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript mootools。Can';无法在iframe中获取DOM元素_Javascript_Iframe_Mootools - Fatal编程技术网

Javascript mootools。Can';无法在iframe中获取DOM元素

Javascript mootools。Can';无法在iframe中获取DOM元素,javascript,iframe,mootools,Javascript,Iframe,Mootools,我有一个基于SocialEngine 4的网站,它使用moo-tools-1.2.5。 有一个带有一些js的iframe,在弹出窗口中打开(带有内置的Smoothbox插件)。 我不能仅仅通过调用$$()就从JS中获取这个iframe的DOM元素,我需要使用这样的乱七八糟的东西: var context = (window.frames[0]) ? window.frames[0] : window; context.$('user_email').set('value', context.$(

我有一个基于SocialEngine 4的网站,它使用moo-tools-1.2.5。 有一个带有一些js的iframe,在弹出窗口中打开(带有内置的Smoothbox插件)。 我不能仅仅通过调用$$()就从JS中获取这个iframe的DOM元素,我需要使用这样的乱七八糟的东西:

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
的别名

我建议您使用from mootools core,它可以扩展iframes,使其获得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)

谢谢您的回答,但我的意思是JS代码位于iframe内部。我不明白为什么它是在父环境中运行的,而不是在它自己的环境中运行的。