Reputation: 3064
I am trying to explore electron and trying to make a simple Mac application. The problem is that I wanted to save the loaded HTML when user closes the application, and upon next start of application the saved html will be loaded.
Now, consider following case: The html which i have loaded initially have some table and items, and during runtime, via javascript I am adding few new rows and values. So the html is modified at runtime. Now when user closes the app, i have to save this html (which is modified). I tried using webContents.savePage but the page which was saved is the HTML which was loaded initially i.e. without runtime changes. How can I do it?
Also I am not able to catch windows.onbeforeunload event, don't know why. But window.closed is triggerd.
Any help?
Upvotes: 1
Views: 1385
Reputation: 51
You can use the 'close' Event from the BrowserWindow to prevent closing the window in the main process.
https://www.electronjs.org/docs/latest/api/browser-window#event-close
Upvotes: 0
Reputation: 1
You can create a File
or Blob
object of document
let file = new File([document.documentElement.outerHTML]
, "file-" + new Date().getTime() + ".html"
, {type:"text/html", lastModified:new Date().getTime()});
Upvotes: 3