Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Javascript Print Function

2 views
Skip to first unread message

Hemant

unread,
Nov 16, 2009, 6:03:38 AM11/16/09
to
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

unread,
Jan 2, 2010, 12:07:33 PM1/2/10
to
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
njsok...@hotmail.com
http://www.nathansokalski.com/

"Hemant" <Hem...@nomail.com> wrote in message
news:uif$CwqZKH...@TK2MSFTNGP06.phx.gbl...

Evertjan.

unread,
Jan 2, 2010, 12:25:49 PM1/2/10
to
Nathan Sokalski wrote on 02 jan 2010 in
microsoft.public.scripting.jscript:

> 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!

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)

0 new messages