[英]cordova-plugin-printer printing raw html instead of rendered html
I am using cordova-plugin-printer for one of my Cordova app.我正在为我的Cordova应用程序之一使用cordova-plugin-printer 。 I have installed the plugin, and also able to access android native printing service .
我已经安装了插件,并且还可以访问android 原生打印服务。 The plugin's print function can be called in app using it's function
cordova.plugins.printer.print();
插件的打印 function 可以在应用程序中调用,使用它的 function
cordova.plugins.printer.print();
as described in the plugin documents here and on it's git repository .如此处的插件文档及其git存储库中所述。
I actually need to print a selected <div>
from the HTML, using JavaScript/jQuery.我实际上需要使用 JavaScript/jQuery 从 HTML 打印一个选定的
<div>
。
But the problem I'm facing is that when I am passing html as a var
this plugin is printing raw HTML, and not the rendered HTML as desired.但是我面临的问题是,当我将 html 作为
var
传递时,此插件正在打印原始 HTML,而不是根据需要渲染的 HTML。 Where as, if I directly pass HTML code, as a parameter, it gives the desired result.其中,如果我直接将 HTML 代码作为参数传递,它会给出所需的结果。
My Example Code:我的示例代码:
When I call当我打电话
cordova.plugins.printer.print('<h1>How r u</h1>');//print as desired.
But when I write code like this:但是当我写这样的代码时:
<div id="printable">
<h1>How are you</h1>
</div>
var printable = $("#printable").html();
cordova.plugins.printer.print(printable);//prints raw html
Can anyone help?任何人都可以帮忙吗? or correct me what am I doing wrong?
或纠正我我做错了什么? seems to be something silly, which I am probably unable to figure out.
似乎很愚蠢,我可能无法弄清楚。
You need to remove line breaks from your html.您需要从 html 中删除换行符。 Try
尝试
var printable = $("#printable").html();
printable = printable.replace(/(\r\n|\n|\r)/gm, '');
cordova.plugins.printer.print(printable);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.