Trigger events in iframe's parent window

前端 未结 4 1475
青春惊慌失措
青春惊慌失措 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:29

    You might try adding a triggering function in the parent document, then calling it as a regular function from the iframe. This should ensure you're triggering the event in the right document context.

    // In Parent
    function triggerComplete () {
      $(document).trigger('complete');
    }
    
    // In iFrame
    window.parent.triggerComplete();
    

提交回复
热议问题