Jack
Jack

Reputation: 11

Javascript window.open(xxx, "download") creates a blank page while download prompt

When I run window.open(file, "download") with safari, it opens a blank page while download prompt and the blank page stays there. I notice firefox opens a blank tab but it's close when download starts. Is there another javascript command/function that will work so there's no blank page opened in Safari?

Upvotes: 1

Views: 12245

Answers (2)

Dan
Dan

Reputation: 21

Call window.open like this (it works in all major browsers):

window.open(file, '_parent', 'download');

Upvotes: 2

BenMorel
BenMorel

Reputation: 36494

Why don't you use window.location = file instead?

Redirecting to the file leads to the same behavior as clicking on a link to that file: you get the download prompt, and the browser stays on the current page!

Upvotes: 5

Related Questions