window.open about browser interception problem analysis and solution _javascript skills
Source: Internet
Author: User
Window.Open is a JavaScript function that opens a new window or changes the original window, but is generally used to open a new window, because modifying the original web address can have another function, which is window.location, He can redirect the page address so that the page jumps to another page.
I now want to say is the window.open function of several use strategy, under normal circumstances, if you directly in JS call window.open () function to open a new window, the browser will intercept you, think you will pop-up ads and other users do not want to get the form, so if you do not want the browser to intercept you, You can change this function to trigger when the user clicks on it, so the browser thinks that the user wants to access the page, rather than you pop it directly to the user.
So the common method is to add the onclick event in the hyperlink, such as <a href= "javascript:void (0)" onclick= "window.open ()" ></a> so the user clicks on the hyperlink, The browser will think it is opening a new link, so it will not intercept.
But sometimes we will encounter want to pop a window, but it is in the Onckick event after the execution, just to bounce out, then will be blocked by the browser, we can use the following methods to avoid, that is, first with window.open open a window, and then modify the address. such as Var tempwindow=window.open (' _blank '); open a window and then use tempwindow.location= ' http://www.baidu.com '; make this window jump to Baidu, This will render the effect of pop-up Baidu window.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service