Windows that can't be opened _____window.open

Source: Internet
Author: User

window.open () is the usual way to open a new window, but it will now be blocked by most browsers, the default is the non-user will open the window, that is, advertising and so on.

But it is possible to open by an event with a link, because it will be assumed that the user is subjective to open another window so it is not intercepted.

There are many ways to solve a blocked problem, and it has not been practiced. This requirement existed in the previous period, when several methods were used, but not in effect, and finally

The way to change location by delay has finally been solved. The following is a practical discussion.

The 1.a tag's direct event will not be intercepted. The code is as follows:

    Links.on (' click ', Function (e) {
E.preventdefault ();
var _this = $ (this);
window.open ('/bookmerchant/fun/');
}

After the 2.ajax request, the new open window operation is intercepted, even if the A-linked event is started. As follows:

Self.addBtn.on (' click ', Function (e) {
/*AJAX Request omitted */
}). On (' Success ', function (res) {
if (Res.code = = 200) {
var cusid = res.data.customerId;
window.open ('/bookmerchant/fun/');
}。
The window.open () is not feasible at this time.
The solutions you see online:
1. Create a tag then, bind the event, and then JS Trigger. This is also intercepted in my actual operation.
2. Open the label window.open () before the request, and then change the location after the request is accepted, so it is possible.
var newtab=window.open (' About:blank ');
/*ajax Request */
}). On (' Success ', function (res) {
if (Res.code = = 200) {
newtab.location.href= '/bookmerchant/fun ';
}
3. Another way is to open the new label window.open (), and then through the settimeout () to delay the setting of location, the same principle should also be feasible (no practice here, so do not dare to say certain).

         

Windows that can't be opened _____window.open

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.