Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2003
    Location
    Portugal
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question page print with limiters java script

    Hi.
    Would need a print a page java script type:

    <SCRIPT LANGUAGE="JavaScript">
    if (window.print) {
    document.write('<form><input type=button name=print value="Imprimir factura" onClick="javascript:window.print()"></form>');
    }
    </script>

    but that would only print a partial part of the page.

    Any ideas ?

  • #2
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What do you mean? window.print() will print the entire page (or entire frameset, if selected). Why do you think it would only print part of the page?

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #3
    New Coder
    Join Date
    Nov 2003
    Location
    Portugal
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry Skyzyx, maybe I was not clear.

    I need a java script to print only part of the page that i can choose.

  • #4
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, you can do that... but... it may be more work than you're up for today.

    Pages designed according to web standards are very, very good at accomplishing this sort of thing. Using correct, validated, semantic code for markup, and using only CSS for text styling and layout (NOT Tables) makes sites not only easier to maintain, but also lowers bandwidth costs, improves accessibility without hardly even trying, and makes printer-friendly pages a snap! Learning these methods is the only way that anyone can ever really progress in web design.

    Now, with that being said (and since I haven't seen the entirety of your code), you could use stylesheets to accomplish this... no JavaScript is required.

    In your web page, I'll have to assume that you are aware what stylesheets are (CSS) and how to use them. If not, then this situation is way unworkable.

    Here's a sample of what you should have:
    Code:
    <link href="default.css" rel="stylesheet" media="screen" />
    <link href="printer.css" rel="stylesheet" media="print" />
    The first line is your normal stylesheet, except that you specify that it is used only for the screen. The second is your stylesheet for determining how the printed page will look. Inside that page, you'll want to figure out what part you want to print out. Once you find that section, there will be code before it and after it. In the code before it, wrap it all in a div tag and add a "printhide" class. Do the same for the code after it. In your printer stylesheet, add the following:
    Code:
    div.printhide { display:none; }
    It may be a bit of work to get it all to work how you want it to (as I said earlier, designing using web standards makes this a breeze), but if you do it right, this will work.

    Hope this helps!

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.


  •  

    Posting Permissions

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