简体   繁体   中英

mootools. Can't get DOM elements within iframe

I have a site based on SocialEngine 4 which uses moo-tools-1.2.5. There's an iframe with some js that opens in pop-up (with built-in Smoothbox plug-in). And I can't get a DOM element of this iframe from JS included into it just by calling $$(), I've needed to use a kludge like this:

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

That's strange and I guess that it is unexpected behavior because JS in standard SocialEngine modules don't work within iframes too.

this is because in 1.2.5, $$ is an alias for this.document.getElements .

I suggest you use the IFrame wrapper class from mootools-core which can extend iframes so they get mootoolsy, you can then do stuff like:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM