PDA

View Full Version : problem with the printing of alternative page



meenakshi
08-16-2008, 04:24 PM
hi forum
i m trying to print two different pages as soon as the form is saved.

i tried to use this command
<A HREF="javascript:window.print()">Print 1st Page</A>
<A HREF="javascript:window.print()">Print 2nd Page</A>

but i was unable to use the link command to force the printer to print the two other pages

print 1st page should print cust1.htm
and print 2nd page should print cust2.htm

any ideas how to go ahead for the same?
smile always:)
anand:)

motormichael12
08-17-2008, 02:18 AM
Try looking here:
http://www.webmasterworld.com/javascript/3524974.htm

jscheuer1
08-17-2008, 12:01 PM
Try looking here:
http://www.webmasterworld.com/javascript/3524974.htm

How does that help? From looking at that thread, there is no solution that works for printing more than one document. Not only that, the solution given there (which was for printing an alternate document) only works in IE - as stated in the thread!

In this thread:

http://www.dynamicdrive.com/forums/showthread.php?t=31688

particularly after I got involved with it (post 21), we figure out a means for printing iframed content across browsers. That might be able to be used for what meenakshi wants to do. But as I recall, the iframes cannot be visibility:hidden; or display:none;, but they could possibly be positioned absolutely out of view of the user and/or have small dimensions.

If you have both pages to be printed in separate windows. Each window could be printed. However it is done though, there might be problems with spooling multiple print jobs, particularly in IE, as its print command routines do sometimes cancel other javascript, I'm not sure if that would apply here or not.

meenakshi
08-23-2008, 06:04 PM
hi
thanks for the reply
first of all i m only using ie for i m working on a standalone machine.
secondly i will be using two different buttons to print two different pages.
so that means that first link willl point different html page and second print link point different html page
i hope this clears my issue
pls help
smile always
anand

meenakshi
08-23-2008, 06:30 PM
hi for convience sake i am attaching the html file with the code
maybe i m not able to explain things in details
this way it might be possible
i have written a short note just next to the form i html file
pls see it and advice how i should go ahead
smile always:)
anand

codeexploiter
08-26-2008, 11:24 AM
1. In the HTML page you've provided contains two body elements though the browser will never show any error, you need to avoid such issues.

2. You will not be able to print the content of two different pages using "window.print()" in another page. "window.print()" is supposed to print the content of the page in which you've furnished that code. For printing some other pages from another page you have to use some sort of frames or AJAX methods.

Below you can find a iframe based method using which you can print two different files from a third file:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<style type="text/css">

</style>
<script type="text/javascript">
function printPg(ifrmname){
if(top.frames[ifrmname]){
top.frames[ifrmname].focus();
top.frames[ifrmname].print();
}
}

</script>
</head>
<body>
<h1>This is the main file from which I want to print two other files</h1>
<div>
<iframe name="one" width="0" height="0" frameborder="0" src="1.htm"></iframe>
<iframe name="two" width="0" height="0" frameborder="0" src="2.htm"></iframe>
</div>
<div>
<a href="#" onclick="printPg('one');return false;">Print One</a>
<a href="#" onclick="printPg('two');return false;">Print Two</a>
</div>
</body>
</html>


(a) In the first iframe I've mentioned the first page which needs to be printed. Like that in the second iframe I've mentioned the second page that needs to be printed.

(b) The width and height of both iframes kept as "0" as we don't want to display the first and second page content in my third file( the file from which am going to print).

(c) From the anchor element's onclick event I've called a JS function and passed the name of the iframes into the function.

Now you should be able to view the printer dialog box. I've checked it in IE 7 and FF 3.0.1 in both it works correctly.

Please find all the files I've used in this case as attachment. Unzip them, keep them together and browse "main.htm" and try to click the links available in the page.

Hope this helps.

meenakshi
09-02-2008, 05:46 PM
hi codex
hi forum
wow this is working to perfection and it is really nice to learn this new way to print without opening the page itself:)
good
thanks once again
smile always:)
anand

meenakshi
09-07-2008, 04:35 PM
hi codex
i am having a problem with the printing
i m using frames to call this page on the right where i enter all the data and then save it and it goes to print using the iframe .here the problem comes.it does not pass the page to printer as it should do and the most funny part is that when i try to do the same thing without frames it does things normally that is print the page as it should do.
pls advice how i should do this for proper functionality
i m attaching the files for your reference.
please click on send for 1st fitting to test the issue
thanks
anand:)
smile always