Home  >  Article  >  Web Front-end  >  HTML无刷新下载文件方法总汇_html/css_WEB-ITnose

HTML无刷新下载文件方法总汇_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 09:11:321050browse

首先要保证有一个后台可以下载文件的方法,这里只总结前端解决方法,所以不对后台做分析,假设现在有一个下载文件的方法/project/download.action。如果不想通过后台直接下载可以看我的另一篇文章《 html使用a标签不通过后台实现直接下载》。

  • 使用a标签

    点击下载

    这里target属性不给也可以,但是页面会闪一下,体验不好。

  • 使用location.href属性

    javascriptfunction downloadFile(url){    location.href=url;}
  • 使用window.open

    javascriptfunction downloadFile(url){    window.open(url);}
  • 使用iframe

    javascript//javascript版本function downloadFile(url){        var iframe = document.createElement("iframe");          document.body.appendChild(iframe);          iframe.src =url;}//jQuery版本function downloadFile(url){    $("body").append($("<iframe/>").attr("src",url);}

    调用
    点击下载

  • 个人推荐第4种方法,比较灵活。

    Statement:
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn