Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

hiding, showing and printing in javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike P - 24 Jul 2007 09:23 GMT
I am trying to print a webpage and making some objects invisible for the
print, and then visible again after.  But my code does not work :

function PrintInvoice()
        {   
           document.getElementById("Button1").style.visibility = "hidden";
           document.getElementById("Button2").style.visibility = "hidden";
           
            window.print();
           
            document.getElementById("Button1").style.visibility = "visible";
           document.getElementById("Button2").style.visibility = "visible";
        }

Can anybody with good javascript skills help?
Sergey Poberezovskiy - 24 Jul 2007 10:28 GMT
rather than iterating every control on the page that should not be printed,
it is advised to use a separate stylesheet (or style rules) for printing in
which you define certain types with display:none. See
http://www.w3.org/TR/REC-CSS2/media.html for more info

> I am trying to print a webpage and making some objects invisible for the
> print, and then visible again after.  But my code does not work :
[quoted text clipped - 13 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***
Mike P - 24 Jul 2007 10:31 GMT
Found the error - it was simply a matter of calling the function without
braces i.e. PrintInvoice instead of PrintInvoice().
Eliyahu Goldin - 25 Jul 2007 08:29 GMT
There are two javascripts events onbeforeprint and onafterprint that are
good for placing this type of code in. It will make sure that the page
prints correctly regardless of the way how you initiate print, even if the
user clicks the browser's Print button.

And the css idea  that the other poster suggested is even better.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

>I am trying to print a webpage and making some objects invisible for the
> print, and then visible again after.  But my code does not work :
[quoted text clipped - 13 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.