zoukankan      html  css  js  c++  java
  • HTML 单击a标签 实现下载文件而不是浏览器打开预览

     
    1. <a d ownload class="down" title="">  
    2. function download(src,name) {
      // 创建隐藏的可下载链接
      var eleLink = document.createElement('a');
      eleLink.href = src;
      eleLink.download = name;
      eleLink.style.display = 'none';
      eleLink.href = src;
      document.body.appendChild(eleLink);
      eleLink.click();
      document.body.removeChild(eleLink);
      }

    3. //js下载文件
    4. case 'show':
      var urls = data.fileurl;

      var three = urls.split(".");
      var last = '.' + three[three.length - 1];
      last = last.toLowerCase();
      if (last == ".pdf") {
      common.CreateAddForm('查看', urls, {
      '100%',
      height: '100%'
      });
      } else {
      download(urls, data.filename);
      }
      break;

  • 相关阅读:
    PHP实现异步调用方法研究
    碰到这个SB错误,'Taglist: Exuberant ctags (http://ctags.sf.net) not found in PATH. Plugin is not loaded.点办
    ubuntu中vim找不到配色方案blackboard
    解决宿主机不能访问虚拟机CentOS中的站点 | 更新CentOS防火墙设置开启80端口访问
    在VMware中为CentOS配置静态ip并可访问网络-Windows下的VMware
    PHP header() http各种状态码大全查询
    JS创建对象的方式
    buuctf-web [极客大挑战 2019]Upload 1
    buuctf-web 新生赛]Upload 1
    buuctf-web easy_tornado 1
  • 原文地址:https://www.cnblogs.com/enych/p/9269494.html
Copyright © 2011-2022 走看看