Ajax request successfully opens new window address _ajax related

Source: Internet
Author: User
Tags commit

Needless to say, the key code looks like this:

Jquery.ajax ({
"type": "Post",
"url": "Http://www.baidu.com", 
"Success": function (rel) {
if ( rel.issuccess) { 
window.open (rel.url, "_blank");
}

this URL request after successful window.open (Rel.url, "_blank"), will be blocked by the browser, unable to open a new window, if the window.open () on the outside of Ajax, the problem is solved , the code is as follows:

var result= "";
Jquery.ajax ({
"type": "Post",
"url": "Http://www.baidu.com", 
"Success": function (rel) {
if ( rel.issuccess) { 
result=rel.url;
window.open (Rel.url, "_blank");
}
}
);
if (result.length>0) {
window.open (result, "_blank");
}

Look below to open a new window after an AJAX response

Recent development has a function, click on a link, to determine whether the current user is logged in, do not log in, you need to pop up a login dialog box, the user login, and then in a new window (tag) to open the link to the URL.

No more, just post the code:

$ (document). Delegate ("A", "click", Function () { 
var ActionURL = $ (this). attr ("href"); 
var ssoaction = function () {window.open (actionurl, ' _blank '); 
if (IsLogin ()) { 
ssoaction (); 
} else { 
popup.show ({login:function () { 
$.ajax ({ 
type: Post), 
dataType: "json", 
URL: "/account/login", 
Data: $ ("Frmlogin"). Serialize (), 
//Send in sync, Avoid pop-up pages being blocked by browsers
Async:false, 
success:function (oData) { 
ssoaction ();} 
}) 
;} return false; 
});

Focus: Need to use synchronous commit, use asynchronous commit, callback inside open new Window (label), can be considered by the browser is malicious behavior.

Related Article

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.