Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger a function when iframe src change?

i have iframe with src like http://remote-domain.com/, and when ever the src is get changed i need to trigger a function like iframeSrcChanged()

<iframe id="iframe" src="http://remote-domain.com/" frameborder="0" width="100%" height="100%" ></iframe>

and when user click about-us inside iframe, the iframe src get changed into

<iframe id="iframe" src="http://remote-domain.com/about-us.html" frameborder="0" width="100%" height="100%" ></iframe>

so this time i need to trigger iframeSrcChanged() function.

Please help me to trigger out this issue.

like image 234
rkaartikeyan Avatar asked Mar 25 '26 00:03

rkaartikeyan


1 Answers

var iframe = document.getElementById("iframe");

iframe.addEventListener("DOMAttrModified", function(event) {
    if (event.attrName == "src") {
       // The "src" attribute changed
    }
});

However this will work only in modern browsers

like image 164
Ricky Stam Avatar answered Mar 26 '26 14:03

Ricky Stam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!