Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide Page while Printing 1

Status
Not open for further replies.

spirit66

Technical User
Joined
Apr 10, 2004
Messages
29
Location
US
I do have a page where when the user clicks "Print Page"
actually it takes to another ASP Page and has "printpage()" javascript function on body load .
i.e
Code:
 <body onload="printpage()">
. The MS Windows Print Dialog box comesup and it Prints Properly . I was wondering if there is a way i can actually hide the print page and still print this page with just the MS Windows Print Dialog box coming up .
Printpage() does this :window.print();

Thanks!!!!
 
Sure! Specify your hidden document to print in the <HEAD> with
Code:
<link rel=alternate media=print href="hiddenDoc.html">
then use window.print(). Even if they select "print" from the menu or right-click > print, it'll still print the hidden doc.


Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
spirit66,

If you can count on the user's browser to support frames or iframes, you can have a "hidden" one of these (width = "0%") and load your page-to-print into that. This way, no new browser windows need-be opened.

Good luck.

--Dave
 
When i try to hide frames using width="0%" it does hide frames but it prints blank screen . I guess this is because windows.print() prins only
the visible parts of the screen .

I also tried <link rel=alternate media=print href="hiddenDoc.html">
with no luck
 
I have printed the contents of a hidden frame in IE6 before.

Can you post some relevant code? Show us your html for your print button and the function it calls 'onclick'. Then show us the body tag and printpage() function of the hidden page.

--Dave
 
I have asp page where the contents are not in print friendly format .It has button
which call this javascript funtion .
Code:
printpage()
{
parent.frames['MAIN'].location = 'xyz.asp?abc=123'
}
so all this function does is redirects to the xyz page .
which it does the right way .

In xyz page i have this
<body onload="printpa()">

printpa does this .

Code:
printpa()
{
window.print();
}
This function also works properly . All i want is not to display xyz page but still print xyz page .

As you mentioned i had this iframe in the body of the xyz page
Code:
<body onload="printpa()">
<iframe width="0%">
contents....heree....asp code ....
</iframe>
</body>
Please bear with me ,I'm relatively new .

Thanks!!!
 
spirit... you may have provided JUST ENOUGH code to find what's wrong...

You do not actually type anything between two IFRAME tags. Any text that goes there is actually an error message that shows up in a user's window if their browser doesn't support IFRAMEs.

Rather, your content should be in a separate file and that file should be mentioned as the 'SRC' in the IFRAME tag:

Code:
<iframe width="0%" src="aspCodeToPrint.asp">
Error message to users without iframe-support: this page relies on IFRAMES.  Your browser does not support them.  Come back when you have a browser that does!
</iframe>

It's in the ASP that you need the function to be included that executes 'window.print();'.

Now... [I think this next part is what you really are asking... I'm not exactly sure]

If you don't want to see ANY PART of xyz.asp at all, then your MAIN frame should be the one that's hidden and xyz won't need an iframe at all (but will still need the printpa() function).

In sum, the page you want printed must include the printpa() function in it. All of this (the page and the function) are part of the same asp and this asp is in a hidden frame.

Follow?

--Dave
 
Including this on your main page should work.
Code:
<link rel=alternate media=print href="xyz.asp?abc=123">
You wouldn't even need to use JavaScript using this method if you didn't want to. What problem are you experiencing?

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
when i try to use this in the main.asp page
Code:
<head>
<link rel=alternate media=print href="xyz.asp?abc=123">
</head>

and try to print this from File/Print options of IE It prints the current window which is main.asp and xyz.asp?abc=123 .

Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top