src.html页面的代码:
other.html页面的代码
下面是alert.html
confirm.html
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>alert 在ie8与ie6下不同</title>
</head>
<body>
<input type='button' id='openPage' value='openPage'>
<script type='text/javascript'>
var fun = function(){
open("other.html");
}
var obj = document.getElementById("openPage");
obj.onclick = fun;
function showAlert(){
window.alert("src.html");
//window.confirm("你是否确定增加?");
}
</script>
</body>
</html>
other.html页面的代码
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>alert 在ie8与ie6下不同</title>
</head>
<body>
<input type='button' id='runOther' value='runOtherPageMethod'>
<script type='text/javascript'>
var fun = function(){
window.opener.showAlert();
}
var obj = document.getElementById("runOther");
obj.onclick = fun;
</script>
</body>
</html>
用ie8打开src.html界面,点击openPage按钮,弹出other.html页面,再点击runOtherPageMethod按钮,发现并没有出现alert;
在ie6,chrome等其它浏览器下都会出现alert。
本人的解决方法:
重新写方法替换alert与confirm,用模态窗口实现阻塞。
/**
*@param {String} msg 提示的信息
*/
function dhcsys_alert(msg){
var userAgent = window.navigator.userAgent;
if (userAgent.indexOf("MSIE 7.0")>0 || userAgent.indexOf("MSIE 8.0")>0) {
window.showModalDialog("alert.html",
{msg:msg},
"dialogWidth:300px;dialogHeight:120px;center:yes;toolbar=no;menubar:no;scrollbars:no;resizable:no;location:no;status:no;help:no;");
}else{
alert(msg);
}
}
/**
*@param {String} msg 提示的信息
*@param {String} YesOrNo 默认焦点在Yes上还是No上 可选值为YES或NO.默认为Yes
*/
function dhcsys_confirm(msg,YesOrNo){
var userAgent = window.navigator.userAgent;
if(userAgent.indexOf("MSIE 7.0")>0 || userAgent.indexOf("MSIE 8.0")>0) {
if(arguments.length==1){
YesOrNo = "YES";
}
return window.showModalDialog("confirm.html",
{msg:msg,YesOrNo:YesOrNo},
"dialogWidth:300px;dialogHeight:120px;center:yes;toolbar=no;menubar:no;resizable:no;location:no;status:no;help:no;");
}else{
return window.confirm(msg);
}
}
下面是alert.html
<html>
<head>
<title>提示信息</title>
</head>
<body style="overflow-y:hidden;">
<table style="width:100%;height:100%;background-color=#c7dffc;">
<tr>
<td>
<table align="center" style="width:250px;height:50px;background='images/logon_bg.jpg'" border=0 cellSpacing=0 cellPadding=0>
<tr>
<td><img src="../skin/default/images/icon-warning.gif"/></td>
<td>
<div id="DivMsg"></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center"><input type="button" id="BtnSure" value="确认" style="width:50px;height:22px;"></td>
</tr>
</table>
<script type="text/javascript">
window.onload = function(){
var divObj = document.getElementById("DivMsg");
var btnObj = document.getElementById("BtnSure");
if (typeof dialogArguments!="undefined" && dialogArguments) {
divObj.innerHTML = dialogArguments.msg;
}else{
divObj.innerHTML = "请为dhcsys_alert方法传入提示信息";
}
btnObj.onclick = function(){
window.close();
};
if (btnObj) {
try {
btnObj.focus();
//btnObj.select();
} catch(e) {}
}
}
</script>
</body>
</html>
confirm.html
<html>
<head>
<title>确认信息</title>
</head>
<body style="overflow-y:hidden;" >
<table style="width:100%;height:100%;background-color:#c7dffc;">
<tr>
<td>
<table align="center" style="width:250px;height:20px;" border=0 cellSpacing=0 cellPadding=0>
<tr>
<td><img src="../skin/default/images/icon-question.gif"/></td>
<td>
<div id="DivMsg"></div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center"><input type="button" id="BtnYES" value="是" style="width:50px;height:22px;"> <input type="button" id="BtnNO" value="否" style="width:50px;height:22px;"></td>
</tr>
</table>
<script type="text/javascript">
window.onload = function(){
var divObj = document.getElementById("DivMsg");
var btnYESObj = document.getElementById("BtnYES");
var btnNOObj = document.getElementById("BtnNO");
var defaultFocus = "YES";
if (typeof dialogArguments!="undefined" && dialogArguments && dialogArguments.msg) {
divObj.innerText = dialogArguments.msg;
defaultFocus = dialogArguments.YesOrNo;
}else{
divObj.innerHTML = "请为dhcsys_confirm方法传入提示信息";
}
btnYESObj.onclick = function(){
returnValue = true;
window.close();
};
btnNOObj.onclick = function(){
returnValue = false;
window.close();
};
if(defaultFocus=="NO"){
btnNOObj.focus();
}else{
btnYESObj.focus();
}
}
window.onunload = function(){
if(!returnValue) returnValue = false;
}
</script>
</body>
</html>