js實現(xiàn)window.open不被攔截的解決方法匯總
本文實例講述了js實現(xiàn)window.open不被攔截的解決方法。分享給大家供大家參考。具體分析如下:
一、問題:
今天在處理頁面ajax請求過程中,想實現(xiàn)請求后打開新頁面,就想到通過 js window.open 來實現(xiàn),但是最終都被瀏覽器攔截了。
二、分析:
在谷歌搜索有沒有解決方法,有些說可以通過新建a標簽,模擬點擊來實現(xiàn),但是測試發(fā)現(xiàn)都實現(xiàn)不了,照樣被瀏覽器攔截。
最后找到了一個折中的辦法,可以實現(xiàn)新頁面打開,但是沒有a標簽的那種直接流量新頁面的效果。
三、實現(xiàn)代碼:
var newTab=window.open('about:blank');
$.ajax({
success:function(data){
if(data){
//window.open('http://www.dhdzp.com');
newTab.location.href="http://www.dhdzp.com";
}
}
})
})
其它方法:
<!--
$(
function()
{
//方法一
window.showModalDialog("http://www.dhdzp.com/");
window.showModalDialog("http://www.dhdzp.com/");
//方法二
var aa=window.open();
setTimeout(function(){
aa.location="http://www.dhdzp.com";
}, 100);
var b=window.open();
setTimeout(function(){
b.location="http://www.dhdzp.com";
}, 200);
var c=window.open();
setTimeout(function(){
c.location="http://www.dhdzp.com";
}, 300);
var d=window.open();
setTimeout(function(){
d.location="http://www.dhdzp.com";
}, 400);
var ee=window.open();
setTimeout(function(){
ee.location="http://www.dhdzp.com";
}, 500);
var f=window.open();
setTimeout(function(){
f.location="http://www.dhdzp.com";
}, 600);
var g=window.open();
setTimeout(function(){
g.location="http://www.dhdzp.com";
}, 700);
var h=window.open();
setTimeout(function(){
h.location="http://www.dhdzp.com";
}, 800);
var i=window.open();
setTimeout(function(){
i.location="http://www.dhdzp.com";
}, 900);
var j=window.open();
setTimeout(function(){
j.location="http://www.dhdzp.com";
}, 1000);
//方法三
var a = $("<a href='http://www.dhdzp.com' target='_blank'>Apple</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
var a = $("<a href='http://www.dhdzp.com' target='_blank'>Apple</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
}
);
//-->
</script>
希望本文所述對大家基于javascript的web程序設(shè)計有所幫助。
相關(guān)文章
JavaScript+Html5實現(xiàn)按鈕復制文字到剪切板功能(手機網(wǎng)頁兼容)
在學習javascript的過程中,遇到一個問題就是基于JavaScript+Html5實現(xiàn)按鈕復制文字到剪切板功能,下面小編給大家分享下我的實現(xiàn)思路,感興趣的朋友可以參考下2017-03-03
利用hasOwnProperty給數(shù)組去重的面試題分享
obj.hasOwnProperty(attr) 判斷是否是原型中的屬性,false就是原型中的屬性,下面這篇文章主要給大家介紹了一道利用hasOwnProperty給數(shù)組去重的面試題,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下2018-11-11

