gpt4 book ai didi

javascript - jquery 处理来自外部 iframe 的事件

转载 作者:行者123 更新时间:2023-11-28 20:25:47 24 4
gpt4 key购买 nike

我的 IFRAME 加载了外部内容(ibnlive.in.com),我无法处理该框架中的点击事件。

这是我的代码,

var iframeDoc = $('#bookcontentHeight').contents().get(0);
// Bind event to iframe document
$(iframeDoc).bind('mouseup', function(e) {
e.preventDefault();
$("#custom-menu").css({ top: e.pageY + "px", left: e.pageX + "px" }).show(100);
});

但是我可以处理 IFRAME 中加载的本地数据,

<iframe src="books/1.xhtml" width="100%" id="bookcontentHeight" frameborder="0" marginheight="0" marginwidth="0" > </iframe>    

我如何处理从外部源加载的点击事件。

最佳答案

您需要将事件处理程序附加到略有不同的对象。尝试:

var targetWindow = iframeDoc.contentWindow || iframeDoc.contentDocument;
if (targetWindow.document) {
var targetDocument = targetWindow.document;

$(targetDocument.body).bind("mouseup", function(){
// event handler
});
}

关于javascript - jquery 处理来自外部 iframe 的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17445982/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com