解决JS弹出新窗口被浏览器阻止的解决方案
2012-11-24 11:26
483 查看
[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还能访问原窗口。
本段内容引自:http://hi.baidu.com/hy0kl/blog/item/486c01f31882e55c352acc1a.html
------------------------------------------------------------------------------
我的代码:
<%@ 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>
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还能访问原窗口。
本段内容引自:http://hi.baidu.com/hy0kl/blog/item/486c01f31882e55c352acc1a.html
------------------------------------------------------------------------------
我的代码:
<%@ 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>
相关文章推荐
- 解决JS弹出新窗口被浏览器阻止的解决方案
- 解决JS弹出新窗口被浏览器阻止的解决方案
- 解决JS弹出新窗口被浏览器阻止的解决方案
- 解决弹出的窗口window.open会被浏览器阻止的问题(自定义open方法)
- 解决弹出的窗口window.open会被浏览器阻止的问题
- 解决弹出的窗口window.open会被浏览器阻止的问题(自定义open方法)
- 解决弹出的窗口window.open会被浏览器阻止的问题
- js弹出新窗口而不会被浏览器阻止的方法
- js解决window.open 被IE弹出窗口阻止程序拦截
- 解决弹出的窗口window.open会被浏览器阻止的问题
- 用JS打开新窗口,防止被浏览器阻止的解决方法
- 解决弹出的窗口window.open会被浏览器阻止的问题
- js windows.open 调用ajax时被一些浏览器阻止弹出窗体的解决方案
- js另开新窗口被浏览器阻止解决方案
- 解决弹出的窗口window.open会被浏览器阻止的问题(自定义open方法)
- 阻止浏览器弹出JS异常
- 根据内容自动调整弹出窗口大小的JS解决方案 选择自 WeekZero 的 Blog
- JS添加可信站点、修改ActiveX安全设置,禁用弹出窗口阻止程序的方法
- 如何解决浏览器弹出窗口的拦截(如:网页支付)
- 解决弹出的窗口window.open会被chrome浏览器阻止的问题