zoukankan      html  css  js  c++  java
  • 保证在浏览器上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);
    }
     
    结论,谷歌可以,但是火狐不行,还是坑.......
  • 相关阅读:
    awk中使用shell变量
    awk的getline命令
    awk的逻辑运算符
    python之re模块
    转载:ensemble计划和数据库
    正则表达式的符号
    awk之match函数
    bash脚本之读取数据
    samtools+bcftools 进行SNP calling
    win10 系统上运行tensorflow三层卷积的方式
  • 原文地址:https://www.cnblogs.com/cx709452428/p/9025349.html
Copyright © 2011-2022 走看看