The element in the iframe triggers the jquery code for the parent window element event

  • 2020-03-30 04:08:17
  • OfStack

For example, the parent window defines an event.

Top:

$(dom1). The bind (' topEvent ', function () {});

So how does the element inside the iframe trigger the parent dom1 event? Like this?

$(dom1, parent. The document). The trigger (' topEvent ');

What seems right is actually misleading.

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

Iframe:

The self $= parent. $;

So the solution is simple:

The parent $(dom1, parent. Doucment). The trigger (' topEvent ');

Call the parent jquery to execute the event.

In other words, iframe should not need to introduce jquery files, just share jquery with the parent window, which is very environmentally friendly.


Related articles: