简体   繁体   English

iframe开始加载时如何捕获事件

[英]How can i catch event when iframe starts loading

For example, user clicked link in iframe and i want in parent.html to show spinner. 例如,用户单击了iframe中的链接,而我想在parent.html中显示微调parent.html And i have cross domain iframe. 而且我有跨域iframe。

bind the click event of any element from the iframe to an event handler in the parent. 将iframe中任何元素的click事件绑定到父级中的事件处理程序。 Using jquery: 使用jQuery:

UPDATE: 更新:

suppose in the parent you have the following function: 假设在父级中您具有以下功能:

var clickHandler = function() {
    alert('Link in iframe clicked');
}

and your iframe contains a link with the class "LinkInIframe", just do this in the iframe: 并且您的iframe包含带有“ LinkInIframe”类的链接,只需在iframe中执行此操作:

$('a.LinkInIframe').click(function(e) {
    parent.clickHandler()
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM