0

Let me keep this simple and straight..

  1. We have a print button in PAGE1

  2. We have a PAGE2 which have data generated using some json and other stuff.

  3. We want to print PAGE2 when I click on a button in PAGE1. (Using Javascript/Jquery)

Please give an idea to attain this functionality.

Thank you.

3
  • I am learning Javascript.. I am ok with loading data from json making some ajax calls...I could only get printing the current page... and I am stuck at printing a page which is dynamic (which is not on screen) Commented Sep 15, 2016 at 4:41
  • Depends on how your pagination is implemented. More. specifically, is it a Single-Page Application (synthetic pages within one document), or a traditional multi-page application (full document reloads)? Commented Sep 15, 2016 at 4:48
  • Just construct the html when you click the print button. Commented Sep 15, 2016 at 4:50

1 Answer 1

1

To print a page that isn't showing you need to use an old hack, hidden iframes.

If you place an "onload" call to window.print() on the page you want to print you can then simply have your button trigger a hidden iframe (1x1) to load that page. Your browser will block any XSS attempt so the javascript to cause a print operation needs to be on the page that is loaded.

Alternatively the child page can usually also access the parent page (as long as they are on the same domain) so you could also have the hidden child page available the entire time (but hidden) and have it register a click event listener on the parent page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.