我有一个弹出窗口,必须跨越多个框架,所以我使用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