I want to detect when user clicks a link in iframe and changes the source of iframe, because I want to resize it. Also I use jQuery. What is the best way to detect this?
Actually I need something like this (this example is in jQuery, it does not work, I imagined this)
$('#iframe').live('load', function(){ alert('src is changed')});
You may want to use the
onLoadevent, as in the following example: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)
Note that you will not be able to access the
contentWindow.locationif the iframe is in a different domain or sub-domain, but theonLoadevent will still fire.