这是我做的一个javascript的两个网页模拟confirm对话框的演示。问题是子窗口没有显示“Confirm Dialog Window。下面是我的两个网页的代码。
网页一:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="有问题!打开和关闭窗口 confirm对话框.aspx.cs" Inherits="打开和关闭窗口_confirm对话框" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var subWindow = null;
function openDialogWindow(msg) {
subWindow = window.open('sub.html', 'subWindow', 'height=150,width=200,top=200,left=200,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no', true);
subWindow.onload = function () {
subWindow.document.getElementById('label1').innerHTML = msg;//********为什么这里失效了!!!!**********//
}
}
function showDialogResult(result) {
document.getElementById('msgBox').innerHTML = 'You han click th"' + result + '"button.';
}
</script>
</head>
<body>
<input type="button" id="btnOpenWindow" value="Show dialog window" onclick="openDialogWindow('Confirm Dialog Window');" />
<br />
<div id="msgBox"></div>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
网页二:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function closeDialogWindow(result) {
window.opener.showDialogResult(result);
window.close();
}
</script>
</head>
<body>
<div id="label1"></div>
<br />
<input type="button" value="OK" id="btnOK" onclick="closeDialogWindow('OK');" />
<input type="button" value="Cancel" id="btnCannel" onclick="closeDialogWindow('Cancel');" />
</body>
</html>