Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In an GWT App, I would like to have a button which when clicked will download a file at a given url. It's a plain text log file (not html) with a .out suffix.

My first attempt is using "window.open()" (tried both gwt and native javascript window.open)

Unfortunately, the browser (tried chrome and firefox and ie) is trying to be smart and notices that the file is a text file, and therefore shows the content in a popup, instead of downloading it. To make matters worse, it seems that the browser is rendering the .out file as if it's html, and messes up all the line breaks and tabs (basically any white spaces).

I'm not in control of the http server that serves the .out file. So I'm looking for a client side solution.

Can someone suggest a solution for me?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
290 views
Welcome To Ask or Share your Answers For Others

1 Answer

It's not possible without modifying the headers coming from the server.

Modern browsers support the download attribute in <a> tags which allows you to trigger a download from a normal link: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#Attributes

Unfortunately, IE11 is not a "modern browser".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...