IE8下,js调用另一页面js方法,不能alert问题

src.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>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值