title: How to properly open a new window on JQuery AJAX Success?
body: <p>I am trying to get a dynamically generated link to open after an ajax request (Specifically after success is returned from the AJAX call). I have a partially working code which works on desktop Chrome and Firefox, but it doesn't work on mobile Safari (the window is not opened.)</p>
  <p>Here is the code (simplified for clarity purposes):</p>
  <pre class="lang-js prettyprint-override"><code>//this function gets called by a click event
  function go(){
  
    var generatedurl
    // generatedurl gets generated
  
    $.ajax({
        url:'url.php',
        type: 'post',
        data: {data},
        dataType: &quot;json&quot;,
        success: function(data) {
                  if (data.status == 'success'){
                    gofunction();
                  } 
                  else if (data.status == 'error') {
                      alert(&quot;error&quot;);
                  } 
        },
        error: function(){
          alert(&quot;error&quot;);
        }
      });
  
    function gofunction()  { 
        window.open(generatedurl, '_blank');
        location.reload();
      }
  
  }
  </code></pre>
  <p>I am aware of <a href="https://stackoverflow.com/questions/20696041/window-openurl-blank-not-working-on-imac-safari">this answer</a>, however when i try to apply it to my code, like this:</p>
  <pre class="lang-js prettyprint-override"><code>//this function gets called by a click event
  function go(){
  
    var generatedurl
    // generatedurl gets generated
  
    var windowReference = window.open(); //this was added
  
    $.ajax({
        url:'url.php',
        type: 'post',
        data: {data},
        dataType: &quot;json&quot;,
        success: function(data) {
                  if (data.status == 'success'){
                    gofunction();
                  } 
                  else if (data.status == 'error') {
                      alert(&quot;error&quot;);
                  } 
        },
        error: function(){
          alert(&quot;error&quot;);
        }
      });
  
    function gofunction()  { 
        windowReference.location = url; //this was changed
        location.reload();
      }
  
  }
  </code></pre>
  <p>For some reason it opens the link even when an error is returned, also <code>location.reload();</code> doesnt fire.</p>
  <p>I'd be thankful for any pointers on what would be the best approach.</p>