Home > Web Front-end > JS Tutorial > body text

An example introduction about iframe

零下一度
Release: 2017-06-30 17:28:36
Original
1152 people have browsed it

For example, the parent window defines an event.

top:
$(dom1).bind('topEvent', function(){});
那么iframe里面的元素怎样触发父窗口dom1的事件呢?这样吗?
$(dom1, parent.document).trigger('topEvent');
Copy after login

It seems correct, but it is actually misleading.

Because the jquery object of the parent window and the jquery object in the iframe are actually two objects (functions), the jquery in the iframe will not trigger events defined by another jquery object. Unless you define it in the iframe like this:

iframe:
self.$ = parent.$;
所以解决的方法很简单:
parent.$(dom1,parent.doucment).trigger('topEvent');
Copy after login

Just call the parent jquery to execute the event.

It is said that iframe should no longer need to import jquery files. It can just share the same jquery with the parent window. This is very environmentally friendly.

The above is the detailed content of An example introduction about iframe. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template