0

Hello friends i am currently working on a project and i am facing a problem . i have javascript code where i get a video's link from its server and it works. but when i want to download the video i click on the download button it took me a new tab and video start playing. and then i right click on the video, then i click on "Save As" to save the video. what will be the way . if i click download button downloading should start there. one thing is that there is a link behind the button that comes from server. hope i could explain my problem.

  // url 
  var vid_url = $("#url").val();

  
  if(isUrlValid(vid_url)){    

    $('#videodownload').button('loading');
    $(".result").hide();
    $("#bar").css("display","block");
    $("#hd").html('');
    $("#sd").html('');
    
    //ajax call
    $.ajax({
      type:"POST",      
      dataType:'json',
      url:'F.php',
      data:{url:vid_url},
      
    
          var img_link = $("#url").val().split("/")[5];
          
         
          $("#title").html(data.title);
          
          // video source
          $('#video').attr('src', data.sd_download_url);
          $("#video")[0].load();
          $("#source").html('<a id="vid_url" href="'+vid_url+'">'+vid_url+'</a>');
          
          # download link
          $("#sd").html('<a href="'+data.sd_download_url+'"  class="btn btn-block btn-color" download="sd.mp4">Download SD</a>');

          // HD video quality download link
          if(data.hd_download_url){
            $("#hd").html('<a href="'+data.hd_download_url+'"  class="btn btn-block btn-color" download="hd.mp4">Download HD</a>');
          }
          
          // button reset
          $('#videodownload').button('reset');

          //show result div
          $(".result").show();
        }

          }
});

//Validations for url
function isUrlValid(url) {
    return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url);
}    
Momo
  • 1
  • 1
  • Could you provide example of video url? – Kudlas Jul 09 '20 at 13:43
  • Does this answer your question? [Force to open "Save As..." popup open at text link click for PDF in HTML](https://stackoverflow.com/questions/3802510/force-to-open-save-as-popup-open-at-text-link-click-for-pdf-in-html) – snwflk Jul 09 '20 at 22:52

0 Answers0