Trigger events in iframe's parent window

前端 未结 4 1483
青春惊慌失措
青春惊慌失措 2020-12-13 10:13

Why is the following not working:

//iframe:
window.parent.$(document).trigger(\'complete\');

//parent window:
$(document).bind(\'complete\', function(){
  a         


        
4条回答
  •  误落风尘
    2020-12-13 10:21

    Answering directly to OP's question: because there is a bug in the first code example.

    You pass the iframe's document object to the parent's $ function. This does not make much sense.

    1. Parent's jQuery instance can not trigger event on DOM object of other window;

    2. Even if it could, it is an iframe's document, but you try to listen for the event on parent's document.

    This would probably work:

    window.parent.$(window.parent.document).trigger('complete');
    

提交回复
热议问题