Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s the best way to reload / refresh an iframe?

I would like to reload an <iframe> using JavaScript. The best way I found until now was set the iframe’s src attribute to itself, but this isn’t very clean. Any ideas?

like image 834
caffo Avatar asked Sep 17 '08 19:09

caffo


People also ask

How do I make sure iframe is loaded?

To check if iframe is loaded or it has a content with JavaScript, we can set the iframe's onload property to a function that runs when the iframe is loaded. document. querySelector("iframe"). onload = () => { console.

What is reload frame in chrome?

Speaking of frames, sometimes you want to reload the upper or lower frame of PCRecruiter. Using the browser's main refresh icon or the F5 keyboard shortcut will reload the whole window and log you out. Instead, right-click inside of the panel you want to reload, and choose Reload Frame from the context menu.

How do I refresh a page using DOM?

The location reload() method in HTML DOM is used to reload the current document. This method refreshes the current documents. It is similar to the refresh button in the browser. Parameters: This method contains single parameter forceGet which is optional.

Can we load HTML in iframe?

The HTML <object> element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin. But keeping your Iframe idea, You could also load your HTML inside your iframe tag and set it as the srcdoc value.


2 Answers

document.getElementById('some_frame_id').contentWindow.location.reload(); 

be careful, in Firefox, window.frames[] cannot be indexed by id, but by name or index

like image 52
Ed. Avatar answered Oct 19 '22 12:10

Ed.


document.getElementById('iframeid').src = document.getElementById('iframeid').src 

It will reload the iframe, even across domains! Tested with IE7/8, Firefox and Chrome.

like image 41
evko Avatar answered Oct 19 '22 11:10

evko