保证在浏览器上word/图片/Excel的下载的表现形式一样

Posted 时空旅人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了保证在浏览器上word/图片/Excel的下载的表现形式一样相关的知识,希望对你有一定的参考价值。

function downloadImage(src) {
console.log(src);
//src="http://192.168.12.50:8181/file/common/png/info_1526003595250.png";
var $a = document.createElement(‘a‘);

$a.setAttribute("href", src);
$a.setAttribute("download", "");
$a.setAttribute("target", "_parent");
 
//var evObj = document.createEvent(‘MouseEvents‘);

if( document.createEvent )
{
var evObj = document.createEvent(‘MouseEvents‘);
evObj.initMouseEvent( ‘click‘, false, false, window, 0, 0, 0, 0, 0, true, true, true, true, 0, null);
$a.dispatchEvent(evObj);
}
else if( document.createEventObject ){
$a.fireEvent(‘click‘);
}
 
//下面这些参数我也不知道是干嘛的,只知道第五个零後面的参数,设置为true的话会新建标签页下载完成后自动关闭
 
//设为false的话下载完成后不关闭
 
//evObj.initMouseEvent( ‘click‘, false, false, window, 0, 0, 0, 0, 0, true, true, true, true, 0, null);
 
//$a.dispatchEvent(evObj);
}
 
结论,谷歌可以,但是火狐不行,还是坑.......

以上是关于保证在浏览器上word/图片/Excel的下载的表现形式一样的主要内容,如果未能解决你的问题,请参考以下文章

用C# Winform程序把图片插入到Excel中的代码

预览word,excel,ppt,pdf图片————使用vue实现

预览word,excel,ppt,pdf图片————使用vue实现

预览word,excel,ppt,pdf图片————使用vue实现

打开wps软件的word,Excel等,总弹出对话框“无法定位程序输入点”于动态链接库”上,如何解决啊!

PPT,Word,Excel,PDF,TXT转换图片