This article describes the solution to the implementation of window.open without being intercepted by js. Share it for your reference. The specific analysis is as follows:
1. Question:
Today, when I was processing the page ajax request, I wanted to open a new page after implementing the request, and I thought of using js window.open to implement it, but it was eventually intercepted by the browser.
2. Analysis:
Is there any solution in Google search? Some people say that it can be achieved by creating a new A tag and simulating clicks, but the test found that it cannot be achieved and it is still intercepted by the browser.
Finally, a compromise solution was found, which could achieve the effect of directly trafficting new pages without the a tag.
3. Implementation code:
The code copy is as follows: $obj.click(function(){
var newTab=window.open('about:blank');
$.ajax({
success:function(data){
if(data){
//window.open('//www.VeVB.COM');
newTab.location.href="//www.VeVB.COM";
}
}
})
})
Other methods:
Copy the code as follows:<script type="text/javascript">
<!--
$(
function()
{
//Method 1
window.showModalDialog("//www.VeVB.COM/");
window.showModalDialog("//www.VeVB.COM/");
//Method 2
var aa=window.open();
setTimeout(function(){
aa.location="//www.VeVB.COM";
}, 100);
var b=window.open();
setTimeout(function(){
b.location="//www.VeVB.COM";
}, 200);
var c=window.open();
setTimeout(function(){
c.location="//www.VeVB.COM";
}, 300);
var d=window.open();
setTimeout(function(){
d.location="//www.VeVB.COM";
}, 400);
var ee=window.open();
setTimeout(function(){
ee.location="//www.VeVB.COM";
}, 500);
var f=window.open();
setTimeout(function(){
f.location="//www.VeVB.COM";
}, 600);
var g=window.open();
setTimeout(function(){
g.location="//www.VeVB.COM";
}, 700);
var h=window.open();
setTimeout(function(){
h.location="//www.VeVB.COM";
}, 800);
var i=window.open();
setTimeout(function(){
i.location="//www.VeVB.COM";
}, 900);
var j=window.open();
setTimeout(function(){
j.location="//www.VeVB.COM";
}, 1000);
//Method 3
var a = $("<a href='//www.VeVB.COM' target='_blank'>Apple</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
var a = $("<a href='//www.VeVB.COM' target='_blank'>Apple</a>").get(0);
var e = document.createEvent('MouseEvents');
e.initEvent( 'click', true, true );
a.dispatchEvent(e);
}
);
//-->
</script>
I hope that the description in this article will be helpful to everyone's web programming based on javascript.