Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement ajax callback to open a new form to prevent browsers from blocking

Shulou Source: shulou.com Published: 2022-06-03 14:15:14 09月17日 Update

This article mainly introduces how to achieve ajax callback to open a new form to prevent browser interception, the article is very detailed, has a certain reference value, interested friends must read it!

Ajax callback to open a new form to prevent browsers from blocking, just do it!

Problem analysis:

Function click_fun () {window.open ("www.baidu.com"); / can open $.ajax ({'url':' ${pageContext.request.contextPath} / activity/savePrizes.htm', 'type':' post', 'dataType':' json', 'data': data, success: function (data) {window.open ("www.baidu.com") / / blocked}, error:function () {}});}

Analysis:

Opening a new form can only be triggered within the click event. Opening the form in the callback function within the click event will be blocked, and the browser will think it is a code such as an advertisement pop-up window.

Solution 1:

Function click_fun_new () {var tempwindow=window.open () / / Open the temporary form first. Since it is triggered within the click event, it will not be blocked by $.ajax ({'url':' ${pageContext.request.contextPath} / activity/savePrizes.htm', 'type':' post', 'dataType':' json', 'data': data, success: function (data) {temp_window.location = "www.baidu.com") / / change the path of the temporary form when callback}, error:function () {tempwindow.close (); / / the callback finds that you can close the previous temporary form}} when you don't need to open the form);}

Solution 2:

Function click_fun_new () {var flag = false; $.ajax ({'url':' ${pageContext.request.contextPath} / activity/savePrizes.htm', 'type':' post', 'dataType':' json', 'data': data,' async':false,// synchronous request success: function (data) {$("# a"). Attr ("href", "www.baidu.com") / / change the href flag = true;// change flag of a tag on the page or created during callback}, error:function () {}}); if (flag) {$("# a") .click () / / simulated click after href property change}} above is all the content of the article "how to implement ajax callback to open a new form to prevent browsers from blocking". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Forms browsers browsing events content time articles code value interests functions guys partners properties advertisements more logos tags knowledge industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Shulou Tech Info Shulou Information Redmi