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.