0

please give me a solution to this. when a button is clicked I want to print a page specified in form action attribute using javascirpt:print() but without redirecting to that page

1
  • incase you are up for it, you can use flash/java midlets on the browser to do this work for you.Id prefer flash over java as im more accustomed to that.but you cab take ure pic on that. Commented Jun 26, 2011 at 13:06

2 Answers 2

1

You can't print a page the browser isn't showing. You can only ask the browser to show the print dialog, which will offer to print the page the browser is currently showing.

You could open a new window, though, and do it that way:

var form = document.getElementById("theForm"); // Assuming the form has `id="theForm"`
var wnd = window.open(form.action);
wnd.print();

If you control the other page, ideally you'd trigger the print call from within the other page when the page is fully loaded. On most browsers, the above works fine, but if I recall correctly on some browsers if the print call happens before the page is fully loaded, you don't quite get what you want...

Note that the code above will only work in direct response to a user action, such as a click on a button. Otherwise, the browser's pop-up blocker will prevent it happening.

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

Comments

0

You might want to consider the following...

You could load the page you want to print in an Iframe and print the contents of the iframe - without redirecting to that (target) page.

You can find more here:http://stackoverflow.com/questions/1261561/printing-a-hidden-iframe-in-ie

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.