Discussion:
Javascript Print Function
(too old to reply)
Hemant
15 years ago
Permalink
Hi,
I want to print on more than one pages .
means in aspx page there are two section if user click on print button i
want print each section on different page on a single click.
Is it possible?
I call this function on button click
function myprint() {

window.parent.Frame1.focus();

window.print();

}



thanks ,

Hemant
Nathan Sokalski
15 years ago
Permalink
I'm not sure if you can do it from the same page, but try doing something
like this:

Use an anchor with target="_blank" as follows:

<a href="firstpagetoprint.aspx" target="_blank">Print</a>

In firstpagetoprint.aspx, include the following in the onload event of the
body tag:

window.print();window.location.replace("secondpagetoprint.aspx");

Include this code in the onload event of the body tag for
thirdpagetoprint.aspx, fourthpagetoprint.aspx, fifthpagetoprint.aspx, etc.
Then, in the onload event of the body tag for lastpagetoprint.aspx, use the
following:

window.print();window.close();

Doing this will basically open a new page in a new window, print it, move to
the next page, print it, and after printing the last page, close the new
window. Unfortunately, because this requires you to have a different URL for
each section you want to print, you may need or want to make an aspx page
that takes a query string to generate the content you want printed for that
specific section. Hopefully this helps!
--
Nathan Sokalski
***@hotmail.com
http://www.nathansokalski.com/
Post by Hemant
Hi,
I want to print on more than one pages .
means in aspx page there are two section if user click on print button i
want print each section on different page on a single click.
Is it possible?
I call this function on button click
function myprint() {
window.parent.Frame1.focus();
window.print();
}
thanks ,
Hemant
Evertjan.
15 years ago
Permalink
Nathan Sokalski wrote on 02 jan 2010 in
...
Serverside code could supply different results with the same url,
using a counter stored in a session variable.

However you could get clientside cashing problems.

Classic ASP example:

<a href="pagenumbertoprint.asp?1" target="_blank">Print</a>

window.print();window.location.replace("pagenumbertoprint.asp?2");

window.print();window.location.replace("pagenumbertoprint.asp?3");

etc

will do nicely using serverside:

<% ' Jscript
var n = Request.querystring;
if (n=1) {
%>
-- first page ---
<%
} else if (n=2) {
%>
-- second page ---
<%
} else if (n=3) {
// etc etc
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Loading...