[英]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()
我有像
http://remote-domain.com/
src iframe,当src被更改时,我需要触发像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中点击about-us时,iframe src会变为
<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. 所以这次我需要触发
iframeSrcChanged()
函数。
Please help me to trigger out this issue. 请帮我解决这个问题。
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 但是,这仅适用于现代浏览器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.