Triggering a jQuery event from iframe

前端 未结 3 1832
失恋的感觉
失恋的感觉 2021-02-07 06:44

Here\'s the scenario, I have events happening from within an iframe and up until now everything is working well. I just ran into the problem where I want to dispatch an event fr

3条回答
  •  梦谈多话
    2021-02-07 06:51

    So this will be the code that lives in your iFrame:

    $('#myElem').click(function() {
    
        window.parent.success_msg();
    
    });
    

    And this code needs to be in the parent window:

    window.success_msg = function() {
    
        // Your code goes here
    
    };
    

    You also need to be running this on a server, either localhost or hosted.

提交回复
热议问题