Download files (movies) with Internet Explorer - javascript

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.

Related

JavaScript and browser PDF support detection

I'm trying to get to work PDF support detection based on a browser where application is running.
First application is checking if a browser is not running on a mobile device. That part works fine - I'm getting Globals.bAllowPdfPreview = true
Then I try to execute code below
if (Globals.bAllowPdfPreview && window.navigator && window.navigator.mimeTypes)
{
Globals.bAllowPdfPreview = !!_.find(window.navigator.mimeTypes, function (oType) {
return oType && 'application/pdf' === oType.type;
});
if (!Globals.bAllowPdfPreview)
{
Globals.bAllowPdfPreview = (typeof window.navigator.mimeTypes['application/pdf'] !== 'undefined');
}
}
It works fine on Chrome but I'm not able to get it to work on FireFox or IE11 - it fails on both statements to verify.
Any tips why is not working?
It came up that Firefox is not working as Mozilla removed the application/pdf MIME type from navigator.mimeTypes object and for IE11 only application/futuresplash and application/x-shockwave-flash are available by default.

Can't get Web Audio API to work with iOS 11 Safari

So iOS 11 Safari was supposed to add support for the Web Audio API, but it still doesn't seem to work with this javascript code:
//called on page load
get_user_media = get_user_media || navigator.webkitGetUserMedia;
get_user_media = get_user_media || navigator.mozGetUserMedia;
get_user_media.call(navigator, { "audio": true }, use_stream, function () { });
function use_stream(stream){
var audio_context = new AudioContext();
var microphone = audio_context.createMediaStreamSource(stream);
window.source = microphone; // Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=934512
var script_processor = audio_context.createScriptProcessor(1024, 1, 1);
script_processor.connect(audio_context.destination);
microphone.connect(script_processor);
//do more stuff which involves processing the data from user's microphone...
}
I copy pasted most of this code, so I only have a cursory understanding of it. I know that it's supposed to (and does, on other browsers) capture the user's microphone for further processing. I know that the code breaks on the var audio_context = new AudioContext(); line (as in, no code after that is run), but don't have any error messages cause I don't have a mac which is required to debug iOS Safari (apple die already >_<) Anyone know what's going on and/or how to fix it?
e: forgot to mention that I looked it up and apparently I need the keyword "webkit" before using Web Audio API in Safari, but making it var audio_context = new webkitAudioContext(); doesn't work either
#TomW was on the right track - basically the webkitAudioContext is suspended unless it's created in direct response to the user's tap (before you get the stream).
See my answer at https://stackoverflow.com/a/46534088/933879 for more details and a working example.
Nothing works on mobile save to home screen apps. I issued a bug report to Apple developer. Got a response that it was a duplicate ( which means they know..no clue if or when they will actually fix it).

saveAs function not working in Safari?

I am trying to display a base64 PDF in an iFrame after a user generates it. For some reason it is extremely unresponsive in Safari and does not display correctly.
My workaround is to detect Safari (among other things) and save a blob. I've tested it on Chrome and Firefox but when the code executes in Safari it just ignores the save as.
Here is the code it should execute:
if(info.browser == 'safari'){
var d = confirm("Click ok to download PDF");
if(d == true){
window.saveAs(blob, 'compare_report.pdf');
}
else{return;}
}

HTML 5 Audio to play MP3 in Internet Explorer 8,9,10

I have tested the following code in Chrome and it works a treat, but Internet explorer doesn't seem to start playing the sound (I am testing in IE9). The rest endpoints returns a data stream with audio/mp3 audio/aac audio/ogg mime types as appropriate...
var url = "/MyServer/services/rest/notifications/sounds/"+soundId+"/"+soundFormat;
var snd = new Audio(url);
snd.addEventListener('ended', function() {
if (this.debug) {
console.info("Sound ended");
}
that.playingSound = false;
});
if (this.debug) {
console.info("Requesting sound to start url:"+url);
}
that.playingSound = true;
snd.play();
Any ideas what might get IE working? I've seen some HTML 5 capability tables that say this is not supported in IE9, whereas other places imply it should work? Maybe this only works if you use the embedded HTML tags instead of code (with preload true), however I need to dynamically load the sound at runtime.

How to save content of the iframe using javascript in Windows 8 store HTML5/javascript app?

I have an iframe control with the source pointing to a page defined in my code. Now How to save content of the iframe using javascript in Windows 8 store app ?I tried the below code but it never goes to any of the below if conditions.
var ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", "http://www.w3schools.com/");
if (ifrm.contentDocument) {
// Firefox, Opera
doc = ifrm.contentDocument;
}
else if (ifrm.contentWindow) {
// Internet Explorer
doc = ifrm.contentWindow.document;
}
else if (ifrm.document) {
// Others?
doc = ifrm.document;
}
This is due to the security changes in WWAs. You'll need to add the destination URL as a valid destination in your manifest.

Categories