0

我的 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>    

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

4

1 回答 1

3

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

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

    $(targetDocument.body).bind("mouseup", function(){
        // event handler
    });
}
于 2013-07-03T10:52:15.550 回答