0

I found another thread on stackoverflow: window.open popup getting blocked during click event. And the top answer seems to solve the problem. But I don't know a lot of JavaScript.

Can you help rewrite the code according the answer:

1) Call window.open just before calling $.ajax and save window reference:

var newWindow = window.open(...);

2) On callback set location property of the saved window reference:

newWindow.location = url;

Maybe it's already in an explicit way. But I don't have any idea how to rewrite the code.

Community
  • 1
  • 1
Neo Um
  • 11
  • 1
  • 1
  • You should post the code you tried first and then you will find many people willing to help you refactor it to work properly. – marteljn Jul 26 '12 at 12:37

1 Answers1

1

Well, keeping in mind the context of the question you linked to, it would be something like this:

var newUrl = 'http://example.com';
var newWindow = window.open('', '_blank');
$.ajax({
  type: "POST",
  url: form_url,
  dataType: 'json',
  data: form_data,
  success: function(data) {
    newWindow.location = newUrl;
  }
});

Of course, you'd have to modify the $.ajax call (url and data, specifically) to match your requirements.

Spectre87
  • 2,374
  • 1
  • 24
  • 37