简体   繁体   中英

How can I prevent popup blocking after ajax call?

I'm working on a JS project where I need for some popups, the problem is that when the popup is being made after an ajax call then the browser will block it but if I make it directly when the user clicking it's working well.

The browser will block this:

$.ajax({
    url: url
}).done(function(data) {
    showPopup();
});

While the browser will let this:

$('#but').click(function(evt) {
    showPopup();
});

The code on Plunker

in browser block popup

please test

$('#ajax_but').click(function() {
  $.ajax({
    async: false,
    url: 'data.json'
  }).done(function() {
    popup();
  });
});

or link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM