Home >Web Front-end >JS Tutorial >window.open analysis and solutions to browser interception problems_javascript skills
window.open is a javascript function. The function of this function is to open a new window or change the original window. However, it is generally used to open a new window, because to modify the original web page address, there can be another function, that is window. location, he can redirect the web page address to jump to another page.
What I am going to talk about now are several strategies for using the window.open function. Under normal circumstances, if you directly call the window.open() function in js to open a new window, the browser will intercept you. , thinking that you will pop up ads and other forms that users don’t want to get, so if you don’t want the browser to intercept you, you can change this function to be triggered when the user clicks, so that the browser thinks it is the user who wants to access this page, not you. Pops up directly to the user.
So a common method is to add an onclick event to the hyperlink, such as In this way, when the user clicks on the hyperlink, the browser will think it is opening a new link, so it will not intercept it. .
But sometimes we will encounter a situation where we want to pop up a window, but it only pops up after the onckick event is executed. At this time, it will be intercepted by the browser. We can do it through the following method To avoid it, use window.open to open a window first and then modify the address. For example, var tempwindow=window.open('_blank'); opens a window, and then uses tempwindow.location='http://www.baidu.com'; to jump this window to Baidu, so that a pop-up Baidu window will appear. The effect is gone.