www.webdeveloper.com
Results 1 to 4 of 4

Thread: printing with javascript

  1. #1
    Join Date
    Oct 2005
    Posts
    2

    printing with javascript

    Hi,

    I'm developing a web page that contians a drop down flash menu in a div tag set to absolute. The site and menu works fine except when I print the div tag that is normally see though now covers the content. I've been fiddling with some scripts and if I try to hide the div tag when the onbeforeprint function is called (the function that is called when you try to print from the browser) then it works on the screen and hides the div tag but it still prints the page with the div tag not hidden and after the print command is finnished it doesn't return the div tag again. Here is my code.

    Code:
       function window.onbeforeprint()
        {
            document.getElementById("flash_menu").style.display = "block";
        }
        
        function window.onafterprint()
        {
            document.getElementById("flash_menu").style.display = "none";
        }
    If any one knows of how to fix this or any tutorials where I can read up on this I will be very greatful.

    Thanks

  2. #2
    Join Date
    Sep 2005
    Posts
    48
    I'm not sure but try changing from "block" to "":
    Code:
      function window.onbeforeprint()
        {
            document.getElementById("flash_menu").style.display = "";
        }

  3. #3
    Join Date
    Oct 2005
    Posts
    2
    Hi,
    Thanks for your help but I managed to figure it out. It turns out that I had it the wrong way arround. Here is the correct working code

    Code:
         function window.onbeforeprint()
        {
    		document.getElementById("table_pos").style.display = "none";
        }
        
        function window.onafterprint()
        {	
    		document.getElementById("table_pos").style.display = "block";
        }
    Thanks again for your efforts

  4. #4
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    onbeforeprint and onafterprint are IE only and completely unnecessary.

    You should be using stylesheets to control this. Simply set up two stylesheets one with media="screen" that displays the div and one with media="print" that doesn't and attach both stylesheets into the page.
    Stephen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles