Safari overwrites page content when saving image file
I use FileSaver to save an image file. It works pretty well in all the browsers but Safari. It does allow to save an image, but it replaces a web-page where saving was called with that image. It's pretty inconvenient in case that page had a dynamic content that can't be recovered by "Back" button.
I call FileSaver the following way:
saveAs(blob, name + '.png', 'image/png');
I couldn't find any workarounds, but maybe it's possible to specify somehow for Safari to open the image in a new tab, s.t. it doesn't change the current page.
I didn't see this before of Safari 9 released on Monday, saw it on a website I made 2 months before.
In the demo it opens a new window. However I can't figure out which code does it.
I found out, that it doesn't happen every time. But I personally have no idea what triggers the difference…
If the saveAs happens after one second from the click that triggered it. So the different is the TIME.
@zerdos, you mean a new tab opens if saveAs is called 1 s later, or a new tab doesn't open in this case?
That is exactly it, it only allows window.open() to open up a new tab if it's done by a user interaction like click event.
It doesn't work by just dispatching a click event since the event has be be event.isTrusted = true
so the blob has to be made synchronous to avoid being overwritten.
I'm still curious doe if we can create a link <a href="blob:xxx-xxx" target="_blank"> and dispatch a click event that is untrusted to open up the page later.
Another option would be to open a about:blank page on a trusted event and then (if the blob is generated asynchronous and lost it's trusted value) then you could redirect that popup later It would be like opening up a download page where it's solo purpose is to be overwritten
Any news?