最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to trigger a function when iframe src change? - Stack Overflow

programmeradmin0浏览0评论

i have iframe with src like /, and when ever the src is get changed i need to trigger a function like iframeSrcChanged()

<iframe id="iframe" src="/" 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=".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.

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

<iframe id="iframe" src="http://remote-domain./" 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./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.

Share Improve this question asked Oct 21, 2013 at 15:33 rkaartikeyanrkaartikeyan 2,0079 gold badges30 silver badges57 bronze badges 1
  • Please see stackoverflow./questions/2429045/… – Tsanyo Tsanev Commented Oct 21, 2013 at 15:41
Add a ment  | 

1 Answer 1

Reset to default 2
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

发布评论

评论列表(0)

  1. 暂无评论