weixin_33736649 2015-10-19 12:00 采纳率: 0%
浏览 33


I am using this https://github.com/eligrey/FileSaver.js to save web page as html.

Following code executes when user clicks download-

var originalstr=$.ajax(
    type: "GET",         
    async: false 

}).responseText  ;
var  str = $(originalstr).find('.toolbar').remove().end();
saveAs(new Blob([ str], {type: "text/html;charset=utf-8"}), "Plan_Enrollment_Show_All.HTML");

I get the response and i am removing a div tag with class name "toolbar" and then i am sending it to saveAs function of the FileSaver.js.

I am getting the web page with "[object Object]" as the content file which got downloaded.

If i don't do any modification and pass the originalstr then i get the proper output. Any help regarding this?

I have taken the escaped html and tried constructing the html by removing the div and it worked. For escaping the html i used this http://www.freeformatter.com/javascript-escape.html#ad-output but when i try to do escaping using escape() function of javascript i get different response.

Demo of removing the tag with class- https://jsfiddle.net/SkyTreasure/zfzocuf2/

  • 写回答

1条回答 默认 最新

  • csdnceshi62 2015-10-19 14:04

    As far as I understood, you needed data/table even after manipulation of the $s variable. I guess as pointed out, you have to say which content has to be displayed. In this case, "div or table" both will give the same result. But, one other good thing is to clone the HTML content(outerHTML function).

    $.fn.outerHTML = function() {
      return $('<div />').append(this.eq(0).clone()).html();
    var $s = $(s).find('.a-IRR-toolbar').remove().end();
    var $t = $(s).find('.a-IRR-toolbar').remove().end().find("div").outerHTML();

    Check this JSFiddle

    Another thing, $t works in most conditions-

    var $t = $(s).find('.a-IRR-toolbar').remove().end().find("div");
    var $t = $(s).find('.a-IRR-toolbar').remove().end().find("table");
    var $t = $(s).find('.a-IRR-toolbar').remove().end().find("div").outerHTML();
    var $t = $(s).find('.a-IRR-toolbar').remove().end().find("div").html();

    All the above values give the same result. But, what is implemented is a good practice.

    Let me know if anything specific is needed.




  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥15 miniconda安装不了
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?
  • ¥15 微信支付转账凭证,如何解决
  • ¥15 在win10下使用指纹登录时,界面上的文字最后一个字产生换行现象
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,下面有仿真图,请根据仿真图来设计c语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word