隐藏

解决JS弹出新窗口被浏览器阻止的解决方案

发布:2014/4/15 23:18:27作者:管理员 来源:本站 浏览次数:1560

[html] view plaincopyprint? 在js中通过open弹出窗口可能会被阻止,我尝试这段代码:            
var flag = window.open(url,"","");            
if(flag==null) {               
alert("您的浏览器启用弹出窗口过滤功能!\n\n请暂时先关闭此功能!") ;            
}      
上面这段代码仅仅是增加了一个提示,让用户更改浏览器设置.但实际上无任何作用.使用下面的解决方案后,在IE中测试,一般不会被阻止,即使被阻止,ie也会弹出让用户选择是否允许弹出窗口.所以说这种解决方案是行之有效的.       ------------------------------------------------------------------------------    
 1.新添加一个Form     
<form id="EmailForm" action="目标页" method="get" target="_blank">  
<input id="emailid" name="emailid"  type="hidden" />//隐藏域,用来放需要传递的参数  
</form>     
注意form的target属性要设置成_blank     
2.提交这个Form     
function btnEditEmail_onclick() {  
document.getElementById("emailid").value=id;//初始隐藏域  
document.getElementById("EmailForm").submit();//提交  
}     
这样,就会打开新窗口定向到目标页了,而且不会被阻止,同时用新窗口的window.opener还能访问原窗口。  
------------------------------------------------------------------------------     
我的代码:  
<%@ page language="java" pageEncoding="utf-8"%>  
<%@ include file="/summer/component/common/sys.jsp"%>  
<%@ include file="/summer/jsp/head/taglibs.jsp"%>  
<html>  
<head>      
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />      
<link href="<c:url value='/css/css.css'/>" rel="stylesheet" type="text/css" />      
<title>密码确认</title>  
<script type="text/javascript">     
function tijiao(){ // 提交      
var password = document.getElementById("password").value;      
var map = new Map();      
map.put('key', 'maintain.checkPassWord');      
map.put('password', password);      
var query = new QueryObj(map, chakanHeTongjiCallback);      
query.send();   
}  
function chakanHeTongjiCallback(query) {      
if(query.getDetail()=='false'){           
alert('密码输入错误,请重试!');           
return;      
}      
var type = document.getElementById("type").value;      
var cpbbh = document.getElementById("cpbbh").value;      
var plx = document.getElementById("plx").value;      
if(type=='1') {
// 投票详情          
toupiao(cpbbh,plx);      
}else if(type=='2') { //统计          
var submitForm =  document.getElementById("tongjiForm");          
submitForm.submit();          
window.close();      
}      
}       
function toupiao(cpbbh,plx){      
var map = new Map();      
map.put('key', 'maintain.judge');      
map.put('cpbbh', cpbbh);      
map.put('plx', plx);          
var query = new QueryObj(map, toupiaoCallback);      
query.send();       
}       
function toupiaoCallback(query) {      
if(query.getDetail()=='false'){          
alert('该测评表没有任何参与投票信息');          
return;      
}      
var submitForm =  document.getElementById("toupiaoxiangqingForm");      
submitForm.submit();      
window.close();       
}        
</script>  
</head>     
<body>  
<center>     
<div>   
<div width="390">
</div>   
<div width="390">请输入您的密码:</div>   
<table>    
<tr><td><input type="password" id="password" name="userPasWord" /></td></tr>   
</table>  
</div>  
<br>  
<br>  
<div>   
<input name="submit" type="submit" onclick="tijiao()" value="提交" class="anniu6" />                 

<input name="submit" type="button" onclick="window.close();" value="关闭" class="anniu6" />  

</div>  

<ui:hidden name="type" value="${type }"></ui:hidden>  

<ui:hidden name="cpbbh" value="${cpbbh }"></ui:hidden>  

<ui:hidden name="plx" value="${plx }"></ui:hidden>  

</center>     

<%-- 统计 --%>  

<form action="../mzcp/voteDetail.do?action=statisticsVoteDetail" id="tongjiForm" method="post"  target="_blank">      

<ui:hidden name="NCpbbh" value="${cpbbh }"></ui:hidden>      

<ui:hidden name="NPlx" value="${plx }"></ui:hidden>  

</form>  

<%--投票详情 --%>  

 <form action="../mzcp/voteDetail.do?action=singleVoteDetail" id="toupiaoxiangqingForm" method="post"  target="_blank">      

<ui:hidden name="NCpbbh" value="${cpbbh }"></ui:hidden>      

<ui:hidden name="NPlx" value="${plx }"></ui:hidden>      

<ui:hidden name="index" value="0"></ui:hidden>  

 </form>  

</body>     

</html>