问题
I am using Jquery plugin PrintThis.js and jquery-1.7.2.min.js to print a specific div of my web page. It works fine in Firfox and IE. But unfortunately its not working on Google Chrome. Actually Google Chrome is printing Complete web page including the Banner, Menus, and buttons as well. I Searched alot on net but unable to get a suitable solution
Here is my sample code
Java Script
$(function () {
$("input:button").click(function () {
$("#print").printThis();
});
});
HTML
<body>
<input type="button" value="print" />
<div id="print">
this is print area, it can be everything. this is print area, it can be everything.this is print area, it can be everything. this is print area, it can be everything.
</div>
</body>
Here in this page in Google Chroome the button will also be printed, But i dont want this button to be printed, and the same code works fine in Firefox and surprisingly in IE it is also working fine
回答1:
I find the following code to work with my chrome installation (version 32.0.1700.102 m) and printThis v1.3.
JS:
$(function () {
$("input:button").click(function () {
$("#print").printThis();
});
});
HTML:
<body>
<input type="button" value="print" />
<div id="print">
this is print area, it can be everything. this is print area, it can be everything.this is print area, it can be everything. this is print area, it can be everything.
</div>
</body>
Here's a fiddle where I receive the successful result: http://jsfiddle.net/NetsydeMiro/dS6qK/
Perhaps it's an issue with the version of printThis that you're using?
Let me know if this fiddle works for you.
来源:https://stackoverflow.com/questions/21477200/printthis-jquery-plugin-issue-in-google-chroome