SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Print Particular section on page!

    i have two layers which i show and hide as per the users requirement...how do i give a link to print the contents of the layer only???
    Caveman
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will open the layer that you want to print, insert that layer into a new window print and then close.

    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="javascript" type="text/javascript">
    
    function printlayer(layer)
    
    {
      var generator=window.open('','name','');
      var layertext = document.getElementById(layer);
      generator.document.write(layertext.innerHTML.replace("Print me",""));
      generator.document.close();
      generator.print();
      generator.close();
    }
    </script>
    </head>
    
    <body>
    
    <div id="Layer1" style="position:absolute; left:52px; top:37px; width:174px; height:118px; z-index:1">This is text one<br>
      <br>
      <a href=javascript:printlayer('Layer1')>Print me </a></div>
    <div id="Layer2" style="position:absolute; left:239px; top:37px; width:174px; height:118px; z-index:1">This is text two<br>
      <br>
      <a href=javascript:printlayer('Layer2')>Print me</a> </div>
    </body>
    </html>
    Let me know if this is what you want?

  3. #3
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gee...thanks a lot..this is of great help...
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought this would work, but it would show the print dialog box, which I don't know if thats what you want.

    But apart from that, thank you

  5. #5
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you are going to use javascript the document.write, when done after the page has loaded, will create a new page.

    so you can use this
    Code:
    <a href="javascript:document.write(document.getElementById('div_2_show').innerHTML)">
    you can even use this with target="_new"
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

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