开发者

Handle "File save as" event in JS

I need: 1) Get data from server by button click. (can ajax) 2) Execute some js dependi开发者_运维技巧ng on the received data. 3) Show standard "File save as" dialog.

It must work in IE7/IE8/FF.

Thanks! And sorry for my crooked english =)


You can call a PHP file using ajax, which looks like this:

header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($fileContent));
header("Content-Disposition: attachment; filename=\"".$fileName."\"");
echo $fileContent;

This will display the "save as" dialog box in all browsers.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜