window. open Simple Implementation Code Not Blocked of Recommendation

  • 2021-07-09 06:38:35
  • OfStack

Examples are as follows:


$("#last").click(function(){
var w=window.open();
setTimeout(function(){
w.location="https://www.ofstack.com";
}, 1000);

return false;
});

window. open is javascript function, the function is to open a new window or this changes the original window, if you directly in js call window. open () function to open a new window, the browser will intercept you, then how to avoid it, interested friends can understand this article may help you learn

window. open is the javascript function, which is used to open a new window or change the original window, but 1 is used to open a new window, because modifying the original web page address, there can be another function, that is window. location, which can redirect the web page address and make the web page jump to another page.

What I want to talk about now is several usage strategies of window. open function. 1 Under normal circumstances, If you call window. open () directly from js to open a new window, The browser will block you, thinking that you will pop up forms that users don't want, such as advertisements, so if you don't want the browser to block you, you can change this function to trigger when the user clicks, so that the browser thinks that the user wants to access this page, instead of popping it up to the user directly.

Therefore, the common method is to add onclick events to hyperlinks, such as < a href="javascript:void(0)" onclick="window.open()" > < /a > When the user clicks on this hyperlink, the browser will think that it is opening a new link, so it will not be blocked.

However, sometimes we want to pop up a window, but it pops up after the onckick event is executed, and it will be intercepted by the browser. We can avoid it by the following methods, that is, opening a window with window. open first, and then modifying the address. Such as var tempwindow = window. open ('_ blank'); Open a window and use tempwindow. location = 'https://www. ofstack. com'; Make this window jump to Baidu, which will show the effect of pop-up Baidu window.


Related articles: