开发者

IFrame on unload refresh parent page

开发者 https://www.devze.com 2023-01-19 02:11 出处:网络
I have an iframe in a page. When the iframe is closed I would like to refresh the parent page. Checking out the iframe element w3 page I see there are no standard events.

I have an iframe in a page. When the iframe is closed I would like to refresh the parent page. Checking out the iframe element w3 page I see there are no standard events.

I considered a polling approach, having the parent page constantly check if the frame is created, and then checking if it is removed and then refreshing, however this approach isn't great. I can imagine sometimes delays between iframe close and page reload if the polling is to infrequent. With a more frequent polling the page would 开发者_如何学编程impact "user experience" (jerkiness).

I'm wondering if there is another approach that does not involve iframe parent communications.


I don't see why you won't use parent-iframe communication. Since everything happens in the page within iframe, and you just need to let the parent page know about this after this happens, the best way is to call a function in parent page so that you can partially refresh the parent page without having to reload the iframe itself. This way:

window.parent.myFunctionInParent('my param');

You can learn the technique step by step in How to refresh parent page partially from page within iframe.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消