简体   繁体   English

如何打印已被javascript更改过的页面?

[英]How can you print a page that has been altered by javascript?

Here is a screenshot of what I have. 这是我所拥有的屏幕截图

The user can alter the page by deleting items, by adding items, or by clicking on items to cross them out. 用户可以通过删除项目,添加项目或单击项目以将其划掉来更改页面。 I want the user to be able to print the page that they have altered with javascript. 我希望用户能够打印使用javascript更改过的页面。 From what I understand, to let the user print, you create a separate file with different stylesheet settings. 据我了解,要让用户打印,您将创建一个具有不同样式表设置的单独文件。

I'm using Rails 4, and I figure I'd use this to create a PDF for the user. 我正在使用Rails 4,我想我会用为用户创建PDF。

1) I don't know how I'd generate the document with the right things deleted, added, and crossed out. 1)我不知道如何在删除,添加和删除正确的内容的情况下生成文档。

2) I'm not exactly sure how I'd generate the document such that it doesn't have things like the navigation (because you don't need that for the list you print out). 2)我不确定我将如何生成文档,使其不具有导航之类的内容(因为您不需要打印出来的列表)。 I was thinking of just hiding it with CSS. 我当时只是想用CSS隐藏它。

1) The changes being made by the customer are client-side? 1)客户所做的更改是在客户端吗? In that case, kept track of all the users changes, and when the user clicks on "print", send all those changes like a parameter to rails so you can render the right information to be printed from your rails action. 在这种情况下,请跟踪所有用户的更改,并在用户单击“打印”时,将所有这些更改(如参数)发送到rails,以便您可以从rails操作中呈现要打印的正确信息。

But usually, on a rails/javascript application, when the user performs different actions with javascript on the client-side, it invokes some ajax code that notifies the rails application about the changes, so you can store the new state on the rails database, so the user can reload the state later. 但是通常,在rails / javascript应用程序上,当用户在客户端使用javascript执行不同的操作时,它会调用一些ajax代码来通知rails应用程序有关的更改,因此您可以将新状态存储在rails数据库中,因此用户可以稍后重新加载状态。 You can also store the state of the application in a session or a temporary cache. 您还可以将应用程序的状态存储在会话或临时缓存中。

2) Thats exactly what I do when I want to customize what the user is printing, I hide the classes that I don't want to get printed, on the html, when including the css, you tell to the browser that css should be applied to the printed documents by including the media print, like: 2)这正是我要自定义用户正在打印的内容时要做的事情,我隐藏了不想打印的类,在html上(包括css时),您告诉浏览器css应该是通过包括媒体打印内容应用于打印的文档,例如:

stylesheet_link_tag "my_style", media: "print"

Nevertheless, on this case, you are not using the browser printing feature, from what I can understand from your Question, you are going to generate a pdf, because of that, you will be ending rendering a view from rails, you can either add a parameter to let the view know that it will be rendering for printing (so you can draw custom css or just avoid rendering the navigation bar) or you can just invoke a different action with custom code/view for generating the pdf. 不过,在这种情况下,您没有使用浏览器打印功能,据我从您的问题中可以理解的那样,您将生成pdf,因此,您将结束从rails渲染视图,您可以添加一个使视图知道将要渲染以进行打印的参数(因此您可以绘制自定义css或避免渲染导航栏),或者可以使用自定义代码/视图调用其他操作来生成pdf。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何验证客户端上的Javascript是否未更改 - How to verify that Javascript on client has not been altered Javascript失败,因为dom已被改变? - Javascript failing because the dom has been altered? JavaScript:调用已在另一个函数中更改的变量? - JavaScript: Calling a variable that has been altered within another function? 我如何转移已输入的值 <input number> 对象转换成javascript而不刷新页面? - How can i transfer value which has been typed in <input number> object into javascript without page refreshing? 如何判断JavaScript文件是否已包含在ASP.NET页面中? - How can I tell whether a JavaScript file has already been included in an ASP.NET page? 有没有人知道即使页面已刷新,我如何保留Javascript变量? - Does anyone know how can I keep the Javascript variable even though the page has been refreshed? 检查页面打印是否已打印,然后将其关闭 - check if the page print has been printed and then close it 您可以在 javascript 中定义的 function 中打印页面吗? - Can you print a page in a function being defined in javascript? 这个搜索页面是如何实现的(javascript,css,jquery?)? - How has this search page been implemented (javascript, css, jquery?)? 如何在javascript中横向打印页面 - How can I print a page in landscape in javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM