开发者

how to print a text area on button click?

开发者 https://www.devze.com 2023-01-14 04:55 出处:网络
I\'m doing a project in codeginiter these days, i want to print just the text area when the print button is clicked? c开发者_开发知识库an you guys help me to achieve this?

I'm doing a project in codeginiter these days, i want to print just the text area when the print button is clicked? c开发者_开发知识库an you guys help me to achieve this?

regards. Rangana


codeigniter is an excellent framework, but unfortunately doesn't quite apply in this case because php is a server side scripting language and printing is done clientside. For printing a given area you'll want to use some javascript, specifying the div you want to print out. I would recommend the jQuery library as it has a print plugin I've used in a few of my projects. So you would use php to define code like this

<div id="content"> ... </div>

<div id="print_button">Print</div>

<script type="text/javascript">
  // javascript goes here, if you were using jQuery 
  // with the PrintArea pluginyou might do...
  $("div#print_button").click(function(){
    $("div#content").printArea([options]);
  });
</script>

Which would then execute client side when the print button is pressed.

Check out jquery here http://jquery.com/

There's also the vanilla window.print() function with setting up a print stylesheet if you don't want to use jQuery.


If you want to define certain elements to be printed only you need to create a separate css stylesheet:

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

Every element which should not be printed can be hidden using display: none;. See this page for more infomation.

0

精彩评论

暂无评论...
验证码 换一张
取 消