Home > Web Front-end > JS Tutorial > How can I detect changes to an iFrame\'s source?

How can I detect changes to an iFrame\'s source?

Linda Hamilton
Release: 2024-11-04 17:47:02
Original
615 people have browsed it

How can I detect changes to an iFrame's source?

Detecting iFrame Source Changes

When an external iFrame's content falls outside your control, monitoring source changes can become challenging. One possible approach is to use the onLoad event handler within the iFrame:

<code class="html"><iframe src="http://www.google.com/" onLoad="alert('Test');"></iframe></code>
Copy after login

This code triggers an alert whenever the iFrame's location changes. While compatible with modern browsers, it may not work in older browsers like IE5 and early Opera.

Another method, applicable when the iFrame displays content within the same domain as the parent page, is to access the source location using contentWindow.location:

<code class="html"><iframe src="/test.html" onLoad="alert(this.contentWindow.location);"></iframe></code>
Copy after login

This technique provides access to the changed source location. However, it is essential to note that these solutions apply to source changes within the iFrame itself and do not detect src attribute modifications made in the parent page.

The above is the detailed content of How can I detect changes to an iFrame\'s source?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template