开发者

Initiating a download with javascript

I need to dynamically initiate a download with javascript. I have seen how people do this by doing something like

window.open("some url", "Download");

but I need to do it without changing the url of the current page (and not using frames if I can help it, or created and destroying a frame dynamically).开发者_开发技巧 Anybody know how to do this?


You don't need window.open(). It's plain ugly and prone to popupblockers (where you have no control over in clients). Just window.location is sufficient if the response header of the requested download URL contains Content-Disposition: attachment. This won't change the current URL in the browser address bar nor the current page, but just pop a Save As dialogue.

E.g.

window.location = 'http://download.winzip.com/winzip145.exe';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜