js实现window.open不被拦截的解决方法汇总
作者:bea
本文实例讲述了js实现window.open不被拦截的解决方法。分享给大家供大家参考。具体分析如下: 一、问题: 今天在处理页面ajax请求过程中,想实现请求后打开新页面,就想到通过 js window.open 来实现,但是最终都被浏览器拦截了。 二、分析: 在谷歌搜索有没有解决方法,有些说可以通过新建a标签,模拟点击来实现,但是测试发现都实现不了,照样被浏览器拦截。 最后找到了一个折中的办法,可以实现新页面打开,但是没有a标签的那种直接流量新页面的效果。 三、实现代码:
本文实例讲述了js实现window.open不被拦截的解决方法。分享给大家供大家参考。具体分析如下:
一、问题:
今天在处理页面ajax请求过程中,想实现请求后打开新页面,就想到通过 js window.open 来实现,但是最终都被浏览器拦截了。
二、分析:
在谷歌搜索有没有解决方法,有些说可以通过新建a标签,模拟点击来实现,但是测试发现都实现不了,照样被浏览器拦截。 最后找到了一个折中的办法,可以实现新页面打开,但是没有a标签的那种直接流量新页面的效果。
三、实现代码:
代码如下:
$obj.click(function(){
var newTab=window.open('about:blank');
$.ajax({
success:function(data){
if(data){
//window.open('http://');
newTab.location.href="http://";
}
}
})
})
其它方法:
代码如下:
<script type="text/javascript">
<!--
$(
function()
{
//方法一
window.showModalDialog("http:///");
window.showModalDialog("http:///");
//方法二 var aa=window.open(); setTimeout(function(){ aa.location="http://"; }, 100);
var b=window.open(); setTimeout(function(){ b.location="http://"; }, 200);
var c=window.open(); setTimeout(function(){ c.location="http://"; }, 300);
var d=window.open(); setTimeout(function(){ d.location="http://"; }, 400);
var ee=window.open(); setTimeout(function(){ ee.location="http://"; }, 500);
var f=window.open(); setTimeout(function(){ f.location="http://"; }, 600);
var g=window.open(); setTimeout(function(){ g.location="http://"; }, 700);
var h=window.open(); setTimeout(function(){ h.location="http://"; }, 800);
var i=window.open(); setTimeout(function(){ i.location="http://"; }, 900);
var j=window.open(); setTimeout(function(){ j.location="http://"; }, 1000);
//方法三 var a = $("<a href='http://' target='_blank'>Apple</a>").get(0); var e = document.createEvent('MouseEvents'); e.initEvent( 'click', true, true ); a.dispatchEvent(e);
var a = $("<a href='http://' target='_blank'>Apple</a>").get(0); var e = document.createEvent('MouseEvents'); e.initEvent( 'click', true, true ); a.dispatchEvent(e); } ); //--> </script>
希望本文所述对大家基于javascript的web程序设计有所帮助。
有用 | 无用
一、问题:
今天在处理页面ajax请求过程中,想实现请求后打开新页面,就想到通过 js window.open 来实现,但是最终都被浏览器拦截了。
二、分析:
在谷歌搜索有没有解决方法,有些说可以通过新建a标签,模拟点击来实现,但是测试发现都实现不了,照样被浏览器拦截。 最后找到了一个折中的办法,可以实现新页面打开,但是没有a标签的那种直接流量新页面的效果。
三、实现代码:
代码如下:
$obj.click(function(){
var newTab=window.open('about:blank');
$.ajax({
success:function(data){
if(data){
//window.open('http://');
newTab.location.href="http://";
}
}
})
})
其它方法:
代码如下:
<script type="text/javascript">
<!--
$(
function()
{
//方法一
window.showModalDialog("http:///");
window.showModalDialog("http:///");
//方法二 var aa=window.open(); setTimeout(function(){ aa.location="http://"; }, 100);
var b=window.open(); setTimeout(function(){ b.location="http://"; }, 200);
var c=window.open(); setTimeout(function(){ c.location="http://"; }, 300);
var d=window.open(); setTimeout(function(){ d.location="http://"; }, 400);
var ee=window.open(); setTimeout(function(){ ee.location="http://"; }, 500);
var f=window.open(); setTimeout(function(){ f.location="http://"; }, 600);
var g=window.open(); setTimeout(function(){ g.location="http://"; }, 700);
var h=window.open(); setTimeout(function(){ h.location="http://"; }, 800);
var i=window.open(); setTimeout(function(){ i.location="http://"; }, 900);
var j=window.open(); setTimeout(function(){ j.location="http://"; }, 1000);
//方法三 var a = $("<a href='http://' target='_blank'>Apple</a>").get(0); var e = document.createEvent('MouseEvents'); e.initEvent( 'click', true, true ); a.dispatchEvent(e);
var a = $("<a href='http://' target='_blank'>Apple</a>").get(0); var e = document.createEvent('MouseEvents'); e.initEvent( 'click', true, true ); a.dispatchEvent(e); } ); //--> </script>
希望本文所述对大家基于javascript的web程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JsRender for index循环索引用法详解
- javascript常用函数归纳整理
- 让html页面不缓存js的实现方法
- js读取cookie方法总结
- jQuery获取对象简单实现方法小结
- js 通过cookie实现刷新不变化树形菜单
- 判断字符串的长度(优化版)中文占两个字符
- javascript根据时间生成m位随机数最大13位
- D3.js 从P元素的创建开始(显示可加载数据)
- jquery 获取 outerHtml 包含当前节点本身的代码
- 如何调试异步加载页面里包含的js文件
- fckeditor粘贴Word时弹出窗口取消的方法
- js中style.display=""无效的解决方法
- Js实现网页键盘控制翻页的方法
- javascript实现iframe框架延时加载的方法
- js中iframe调用父页面的方法
- js防止页面被iframe调用的方法
- escape函数解决js中ajax传递中文出现乱码问题
- js防止DIV布局滚动时闪动的解决方法