0

Is there a way to save cookie from a local webpage on computer as a text file? I have a local webpage which has some text data inside, the only way i could save these text was using cookie. I have already tried activeX object to create a text file but its only available on IE. Is there any better way?

Updaet: I have used this code, but it does not work in IE

function download(filename, text) {
    var pom = document.createElement('a');
    pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    pom.setAttribute('download', filename);

    if (document.createEvent) {
        var event = document.createEvent('MouseEvents');
        event.initEvent('click', true, true);
        pom.dispatchEvent(event);
    }
    else {
        pom.click();
    }
}
Adi
  • 35
  • 11

1 Answers1

1

No. You don't have access to the local file system as it would be a huge security risk.

Besides cookie's, another option to store data locally would be local storage

Asons
  • 84,923
  • 12
  • 110
  • 165
  • but it means i can't have it as a file again – Adi Feb 21 '16 at 18:47
  • @adonis No it doesn't, it means you can store the file content in local storage and then when you need it, read it back, as with any other file, like a cookie which in fact is stored as a file. – Asons Feb 21 '16 at 18:50
  • @adonis Is the content meant for your web app to read back and fourth? – Asons Feb 21 '16 at 18:54
  • I have used this one but it does not work in IE – Adi Feb 21 '16 at 20:06
  • @adonis If that is what you looking for (your question update), follow the duplicate link, there is several answer which cover more or less all you need – Asons Feb 21 '16 at 20:12