Is it possible to call Javascript function in parent document from JS in iframe?

前端 未结 1 1498
清酒与你
清酒与你 2021-01-15 13:35

Both the iframe and the parent document are on the same domain. What I would like to do is give the js running in the iframe a callback function that resides in the parent d

相关标签:
1条回答
  • 2021-01-15 13:56

    Yes you can - I've done this many times before in a previous job (... their "software" was basically 1,000 frames and a tabbed document).

    Assuming you have this code in your top frame:

    function blah() { alert("it worked!"); }
    

    You can call this in the iframe...

    top.blah();
    

    Also, you can have the parent call down into the child, but the other way around is easier in my opinion.

    0 讨论(0)
提交回复
热议问题