是否可以制作一个打印网站许多页面的按钮?

时间:2016-10-17 14:37:23

标签: javascript jquery html ruby-on-rails printing

我必须创建一个按钮,可以打印我正在处理的网站的许多页面。

我尝试将我需要打印的页面的所有html添加到文档中。 我的想法是打印感谢window.print(),但由于每个页面的javascript内容(使用dom),我有很多错误。

这是我目前的代码:

  var homeInnerHTML = document.documentElement.innerHTML;
  var htmlToPrint = "";
  <% User.all.order(:name).each do |user| %>
  <% Project.where(chief: user.id).order(:title).each do |project| %>
  $.get("/sheet?id=<%= project.id %>", function(data) {
    htmlToPrint += data;
  });
  <% end %>
  <% end %>
  function printAll() {
    document.open();
    document.write(htmlToPrint);
    document.close();
    window.print();

    document.open();
    document.write(homeInnerHTML);
    document.close();
  }

我对于我能做什么没有任何其他想法,如果它以良好的用户体验存在一种巧妙的方式来做到这一点。

0 个答案:

没有答案