File download not working on firefox

download, firefox, javascript

Solution

This should work (I figured it out by looking through the FileSaver.js code):

function onSaveJPG(url,n){
    var save = document.createElement('a');
    save.href = url;
    save.download = 'Image no '+n+'.jpeg' || url;
    var event = document.createEvent("MouseEvents");
        event.initMouseEvent(
                "click", true, false, window, 0, 0, 0, 0, 0
                , false, false, false, false, 0, null
        );
    save.dispatchEvent(event);
}

(the main problem is that you need to use a MouseEvent type event for firefox rather than an Event. This code will also work on Chrome).

Problem

I have written this piece of code which is working perfect on Google Chrome and Opera but not working on Firefox ``` function onSaveJPG(url,n){ var save = document.createElement('a'); save.href = url; save.target = '_blank'; save.download = 'Image no '+n+'.jpeg' || url; var event = document.createEvent('Event'); event.initEvent('click', true, true); save.dispatchEvent(event); (window.URL || window.webkitURL).revokeObjectURL(save.href); } ``` What is wrong? please guide me.

Original source