I am trying to have a button that users can click to download a file, but the file may not exist because it is a zipped file of other files and has to be generated. I am checking this with AJAX but once I recieve a proper URL I'm not sure how to have the user download it.
window.open(link, '_blank'); tries to open the window to download the file, but most browsers prevent this and treat it as a pop-up. What is the best practice for having a user download a file like this? Thanks.
Here is the JS function I am using for reference:
function getDownloadedFiles() {
    var INTERVAL_TIME = 3000,
        $projectView  = $('#project-view'),
        id            = $projectView.data("project-id");
    $.ajax({
        type: "GET",
        url: AJAX_URL + id,
        success: function(data) {
            if (data.success) {
                var link =  data.profiler.link;
                window.open(link, '_blank');
            } else {
                setTimeout(getDownloadedFiles, INTERVAL_TIME);
            } 
        }
    }); 
} 
 
     
    