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>
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>
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!