Home  >  Article  >  Web Front-end  >  How to Reload an iFrame in JavaScript Without Messy Code?

How to Reload an iFrame in JavaScript Without Messy Code?

Susan Sarandon
Susan SarandonOriginal
2024-11-15 17:53:03953browse

How to Reload an iFrame in JavaScript Without Messy Code?

Reloading iFrames with JavaScript

Want to refresh an iframe without compromising code aesthetics? Read on to discover a better solution than setting the src attribute to itself.

Problem:

How do I reload an iframe using JavaScript without resorting to untidy code practices?

Answer:

Leverage the contentWindow property:

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

Note: In Firefox, accessing window.frames[] by id doesn't work. Instead, use name or index.

The above is the detailed content of How to Reload an iFrame in JavaScript Without Messy Code?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn