iFrame src change event detection?

前端 未结 7 1325
夕颜
夕颜 2020-11-22 08:02

Assuming I have no control over the content in the iframe, is there any way that I can detect a src change in it via the parent page? Some sort of onload maybe?

My l

相关标签:
7条回答
  • 2020-11-22 08:51

    You may want to use the onLoad event, as in the following example:

    <iframe src="http://www.google.com/" onLoad="alert('Test');"></iframe>
    

    The alert will pop-up whenever the location within the iframe changes. It works in all modern browsers, but may not work in some very older browsers like IE5 and early Opera. (Source)

    If the iframe is showing a page within the same domain of the parent, you would be able to access the location with contentWindow.location, as in the following example:

    <iframe src="/test.html" onLoad="alert(this.contentWindow.location);"></iframe>
    
    0 讨论(0)
提交回复
热议问题