Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report