Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-6
rated 0 times [  0] [ 6]  / answers: 1 / hits: 17635  / 14 Years ago, fri, july 2, 2010, 12:00:00

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')});

More From » jquery

 Answers
34

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



<iframe src=/test.html onLoad=alert(this.contentWindow.location);></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)



Note that you will not be able to access the contentWindow.location if the iframe is in a different domain or sub-domain, but the onLoad event will still fire.


[#96357] Tuesday, June 29, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzjenseny

Total Points: 409
Total Questions: 93
Total Answers: 106

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
;