Js implementation window.open not blocked solution summary

  • 2020-03-30 04:13:15
  • OfStack

This article illustrates an example of how js window.open can be implemented without being blocked. Share with you for your reference. Specific analysis is as follows:

I. problems:

Today, in the process of handling page ajax requests, if you want to open a new page after implementing the request, you want to do it through js window.open, but all of them are blocked by the browser.

Ii. Analysis:

Google search there is no solution, some say that can be through the new a TAB, simulation click to achieve, but the test found that all can not achieve, still blocked by the browser.
Finally, I found a compromise, which can achieve the effect of new page opening, but no a tag of the kind of direct traffic new page.

Iii. Implementation code

$obj.click(function(){
 var newTab=window.open('about:blank');
 $.ajax({
  success:function(data){
   if(data){
    //window.open('//www.jb51.net');
    newTab.location.href="//www.jb51.net";
   }
  }
 })
})

Other methods:

<script type="text/javascript">
<!--
$(
function()
{
//Method 1
window.showModalDialog("//www.jb51.net/");
window.showModalDialog("//www.jb51.net/");
  //Method 2
var aa=window.open();
setTimeout(function(){
aa.location="//www.jb51.net";
}, 100);
  var b=window.open();
setTimeout(function(){
b.location="//www.jb51.net";
}, 200);
  var c=window.open();
setTimeout(function(){
c.location="//www.jb51.net";
}, 300);
  var d=window.open();
setTimeout(function(){
d.location="//www.jb51.net";
}, 400);
  var ee=window.open();
setTimeout(function(){
ee.location="//www.jb51.net";
}, 500);
  var f=window.open();
setTimeout(function(){
f.location="//www.jb51.net";
}, 600);
  var g=window.open();
setTimeout(function(){
g.location="//www.jb51.net";
}, 700);
  var h=window.open();
setTimeout(function(){
h.location="//www.jb51.net";
}, 800);
  var i=window.open();
setTimeout(function(){
i.location="//www.jb51.net";
}, 900);
  var j=window.open();
setTimeout(function(){
j.location="//www.jb51.net";
}, 1000);
  //Method 3
var a = $("<a href='//www.jb51.net' target='_blank'>Apple</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
  var a = $("<a href='//www.jb51.net' target='_blank'>Apple</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
}
 
);
//-->
</script>


Related articles: