0

I am using jquery Print Plugin

    $(document).ready(function() {
            
            $(".printButton").printPage({
                url: "pages/report.html",
                attr: "href",
                message:"Your document is being generated"
            });

        });

Jsp Page with the above script

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>

   <script>
       
       $(document).ready(function() {
            
            $(".printButton").printPage({
                url: "pages/report.html",
                attr: "href",
                message:"Your document is being generated"
            });

        });
    </script>

</head>
<body>
    <h1>Press Yes to Print </h1>
    <p><a class="printButton" href='exception.jsp'>Yes</a></p>
</body>
</html>

When first time open the page, and press yes , it print in one time and when I open the page second time , on pressing yes, it print 2 pages on a single click, and third time it print three pages on a single click.

Its means on every click ,jquery print plugin library load again and again. How can we control this?

Community
  • 1
  • 1
Shahid Ghafoor
  • 2,991
  • 17
  • 68
  • 123
  • 1
    You should learn using CSS's `media=print` to keep special style sheet for printers only. And in that style sheet keep `display:none` for header/footer etc. refer to http://webdesign.about.com/cs/css/a/aa042103a.htm and http://stackoverflow.com/q/401623/946170 – Imdad Jun 12 '12 at 13:19
  • x2 to what imdad says, that way you dont need another jq plugin just to do this. – NDBoost Jun 12 '12 at 13:20
  • That's an old plugin dependent on an old jQuery version and using old API (e.g. `live`). I would say, get rid of it, and use a print style as per @Imdad's suggestion. – karim79 Jun 12 '12 at 13:22

3 Answers3

1

There is no problem , with your side. Edit the jquery plugin library in the following way.

Add the following

this.die();

after the following statement

$.extend(pluginOptions, options);

This will work fine!

Both FM
  • 770
  • 1
  • 14
  • 33
0

The plugin has no problem, since it use live you need to add it to your page code, not in the ajax call.

Granted maybe I (I am the author) should not have been using event delegation for that, it was a requirement of the project at the time, I will probably change it so it bind itself to the dom with on().

As for the other comments, you guys are missing the point. This plugin is use in webapps on print buttons so you can for example, print a special datagrid directly. it loads the url in a iframe and print it, so you need your print css obviously.

The Orca
  • 1,250
  • 2
  • 17
  • 31
  • LOL... Dear, I have not stated in the answer that the plugin has problem. I have just asked to insert an piece of line in it. As you stated that ......., not in the ajax call. I know this working fine with limited scope. If you update your plugin, as you asking that you change it now, then its scope will increase. It should support ajax call and auto printing without clicking because at this time we can use only trigger for auto printing etc etc. and third thing also support auto page size for printer. – Both FM Jun 13 '12 at 20:26
  • Just downloaded your print plugin. Does it handle elements going over pages. I have a div that needs to stay together. So I don't want half on one page, and half on another. Is this possible? – Thomas Williams Nov 14 '16 at 14:26
-1

not really sure what you want to print, exception.jsp or pages/report.html. What could be happening is that you're defining too many parameters.

From checking the plugin it seems to me you just need to set the href in the <a> to the url of the page you want to print and that's it, the other parameters just let you specify something other than the href (which it uses by default). So try removing url and attr from the jquery call, and change the href in the <a> to 'pages/report.html' (if that's the page you want to print). Not sure what exception.jsp is supposed to do.

Rodolfo
  • 4,155
  • 23
  • 38
  • 1
    Dear, if url: "pages/report.html" is not accessible, then exception.jsp page call. plz refer jquery pluhin as mentioned above – Shahid Ghafoor Jun 12 '12 at 16:34