A simulated user clicking on a new page will not be blocked by the browser

  • 2020-03-30 02:32:54
  • OfStack

If you've ever used window.open, you've encountered a browser block that prevents the page from popping up. Let's change our thinking. Under what circumstances does a new page pop up without being blocked by the browser? Such as < A / > Labels don't; So we just simulate the user to actively click on this. A / > The tag will have no interception problem.

First define the HTML tag:
 
<a href="" id="alink" target="_blank" style="display: none"><span id="spanlink">test</span></a> 
<input type="button" value=" Click me to pop up a new page " onclick="targetClick()" /> 

And then in JS give < A / > Tag assignment and click event:
 
function targetClick() { 
$("#alink").attr("href", "http://www.163.com"); 
$("#spanlink").click(); 
return false; 
} 

OK, the next page pops up and is clear.

Related articles: