This time I will show you how to operate the iframe element to trigger the parent window elementevent, what are theprecautionsfor operating the iframe element to trigger the parent window element event, the following is a practical case, Let’s take a look.top:
$(dom1).bind('topEvent', function(){});
So how do the elements in the iframe trigger the event of the parent window dom1? Is that so?
$(dom1, parent. document ).trigger('topEvent');
It seems correct, but it is actually misleading.
Because thejqueryobject of the parent windowand the jquery object in the iframe are actually two objects (functions), the jquery in the iframe will not trigger another jquery Object defined events. Unless you define it in the iframe like this:
iframe:
self.$ = parent.$;
So the solution is very simple:
parent.$(dom1,parent.doucment).trigger('topEvent');
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.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
The jQuery plug-in implements interlaced table color changes and interacts with mouse events
The above is the detailed content of How to operate iframe element to trigger parent window element event. For more information, please follow other related articles on the PHP Chinese website!