Browser blocks new windows (window.open or New window form submission)

Source: Internet
Author: User

When writing JS, often appear in the browser will prevent the use of JS write window.open code, but, not every time will block, it will only prevent specific circumstances of the window.open. Because it is impractical for browsers to block window.open code by default, the following is a summary of the window.open blocking from the Chrome browser:
Browsers do not prevent users from actively initiating window.open methods, and browsers generally block window.open that are not actively initiated by users.
Here is a question, what is called the user to initiate.
The following code in the execution process is the user initiative to initiate
Http://www.baidu.com ', ' _blank '); > Baidu
The following code is considered unsolicited by the user during execution:
http://www.baidu.com ', ' _blank ')},2000); " > Baidu
That is, after a user triggers an event, the window.open performed by the event handler function is considered reasonable and will not be blocked, but if the execution of the window.open asynchronously is blocked by the browser because the browser does not think it is the user's main sponsor, But the JS code itself originated. Here is related to the JS front-end code often used in the AJAX call, if the use of Ajax with asynchronous execution (the default is asynchronous execution), then often appear window.open will be blocked. The solution is to set Ajax to sync.
$.ajax ({
Async:false,//IS setting this most critical Ajax sync
Type: ' POST ',
Url:ctx + "/sales/submitbank",
Data:orderpost,
Success:function (datas) {
result = Datas;
}
});
The above description also applies to form submission
DWR can override parameters directly:
Async:false can

Turn from: click

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.