3
\$\begingroup\$

I have a web page containing n pages of paged data, showing 20 records at a time. The front end has a link to another page that opens the same data, but without the paging and calls window.print on document.ready.

On my paged content view I have a link:

<a href="printallthisstuff.php" target="blank">Print all items</a>

In printallthisstuff.php I have:

$(document).ready(function(){
    window.print();
});

printaallthisstuff.php can be a very large document, taking several seconds to load. What would be a better way of doing this?

\$\endgroup\$
1
  • \$\begingroup\$ Give the code you just gave, it should be fine. However, I have a gut feeling that it's your PHP that's slow. You should put the PHP code here instead. Additionally, you could head over to StackOverflow to ask for alternative loading methods and UX SE for ways to trick your user into not getting bored waiting. \$\endgroup\$
    – Joseph
    Commented Sep 21, 2015 at 20:47

1 Answer 1

1
\$\begingroup\$

I'd suggest that you do:

<a href="print_frame.html" target="blank">Print all items</a>

where print_frame.html is a simple page that displays an animated loading gif, and contains js that makes an ajax call to printallthisstuff.php. The success callback for that ajax call will then replace the body content (which currently displays loading.gif) with the html returned from printallthisstuff.php, and call print, as you are doing now.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.