0

A page contains a player where you can view videos from a given list. Videos which are currently running in the player should be downloadable to disk. So there is a button download beside the player which starts a pure javascript function downloadClip(). This is the code :

function downloadClip() {
  if (media.currentSrc="") return;
  var url =media.currentSrc;
  var file = url.substring(url.lastIndexOf('/')+1);

  // Mac -> works with Safari 8.0.6, FireFox 37.0.2, Chrome  41.0.2272.64 
  // WIN -> works with FireFox 38.0.5, Chrome  43.0.2357.130m 


  if (!window.ActiveXObject) {
     var hyperlink = document.createElement('a');
     hyperlink.href = 'loadmovie.php?file='+file;
     hyperlink.download = file;
     var mouseEvent = new MouseEvent('click', {
            view: window,
            bubbles: true,
            cancelable: true
          });
     hyperlink.dispatchEvent(mouseEvent);
    }
    // for IE
    else 
      if ( !! window.ActiveXObject && document.execCommand)     {
         var _window = window.open(media.currentSrc, '_blank');
         _window.document.close();
        _window.document.execCommand('SaveAs', true, url || media.currentSrc)
        _window.close();
    }
}

I got this script here from SA but I must say I do not know if this is the best (simple) way to download files. Anyway it works fine for browser noted above. My problem is IE. As I found out ActiveXObject is hidden from the DOM starting with IE11 , as written here. But I only have access to IE11 on a provided laptop and I cant test earlier vesions. So I am asking if anyone can give me hints / support to the question how to download files to disk with :

a) IE11 (no ActiveXObject support anymore
b) IE10 and before.

Please note: I use only pure js

Any link to official docs and code samples are welcome.

Community
  • 1
  • 1
Ben
  • 677
  • 5
  • 19
  • You could try forcing IE to use older versions via X-UA-Compatible (see http://stackoverflow.com/q/10445781/3497425 ). Also, IE has developer tools (press F12), where you can manually select ie version used. – kecer Jul 07 '15 at 08:30
  • @kecer - Thanks for your proposal. As I understand from the linked discussion is that if you use the X-UA-Compatible metatag you limit your browser with an emulation only to this given version, i.e. IE=8. I need in fact a way to cover all possible versions with and without ActiveXObject support. – Ben Jul 07 '15 at 08:46

0 Answers0