我有一個彈出窗口,必須跨越多個框架,所以我使用window.createPopup來獲得這個工作。 (IE6,7和8)彈出窗口中的空DOM
下面是我使用創建彈出功能:
function ShowMyPopup() {
notificationPopup = window.createPopup();
$(notificationPopup.document.body).load("/notification.html");
notificationPopup.show($(sourceFrame.document.body).width() - 510, $(sourceFrame.document.body).height() - (510 - $(sourceFrame.document.body).height()), 500, 500, sourceFrame.document.body);
}
這似乎是工作得很好。我應該看到彈出窗口。問題是,無論我做什麼,我似乎無法訪問生成的彈出窗口中的任何DOM元素。我已經嘗試了各種jQuery方法以及getElementById,並且都返回NULL。下面是notification.html的內容:
<html>
<head>
<script type="text/javascript">
$(document).ready(function() {
alert($(document).html());
alert($("#divNotification").html());
alert(document.getElementById("divNotification"));
});
</script>
</head>
<body>
<div id="divNotification" onclick="$(this).toggle();">
<h3>Some Notification!</h3>
Testing 1234...
</div>
</body>
</html>
我看到三個警報,所以我知道jQuery是工作,但所有三個警報簡單地顯示「NULL」。如果我點擊生成的div,onClick會觸發,但我會收到「Object Expected」錯誤。
這是怎麼回事?
在您的演示中,不包括jQuery。 – 2012-04-16 18:48:15
您試圖通過使用'$(document).html()'來獲取文檔的html。你應該使用'(「html」)。html()'。這導致第一個警報返回null。另外兩個可能是由於您嘗試訪問DOM時沒有準備好DOM導致的。嘗試添加超時以延遲它們。 – 2012-04-16 19:08:15
Rob - jQuery包含在父頁面中,這些apparents允許它在彈出窗口中工作。 (或者可能不是?)無論如何,如果我還在notification.html – RMD 2012-04-16 19:21:10