Heim  >  Artikel  >  Web-Frontend  >  HTML无刷新下载文件方法总汇_html/css_WEB-ITnose

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

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

首先要保证有一个后台可以下载文件的方法,这里只总结前端解决方法,所以不对后台做分析,假设现在有一个下载文件的方法/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种方法,比较灵活。

    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn