SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    which is better, or what

    Which is the better way, or what other ways can it be done.

    Situation

    I want if a user clicks on the print link to reload the page using a differnt style sheet. I am going use a hyperlink with a the url + parms like a GET post.

    Code:
    <?
    if( isset($HTTP_GET_VARS['print']))
    	{
    		//**METHOD ONE**
    		$cssurl = AddSlashes('<link href="css/stylename_print.css" rel="stylesheet" type="text/css" />');
    		echo $cssurl;
    		
    		//**METHOD TWO**
    		//echo "<link href=\"css/stylename_print.css\" rel=\"stylesheet\" type=\"text/css\" />";
    	}
    	else
    	{
    	    //**METHOD ONE**
    		$cssurl = AddSlashes('<link href="css/stylename.css" rel="stylesheet" type="text/css" />');
    		echo $cssurl;
    		
    		//**METHOD TWO**
    	    //echo "<link href=\"css/stylename.css\" rel=\"stylesheet\" type=\"text/css\" />";
    	}
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Massachusetts
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about this...

    PHP Code:
    <?php
    if( isset($_GET['print']))    {      
            echo 
    '<link href="css/stylename_print.css" rel="stylesheet" type="text/css" />';    
    } else    { 
            echo 
    '<link href="css/stylename.css" rel="stylesheet" type="text/css" />';    
    }
    ?>
    Note: The $HTTP_GET_VARS array is deprecated, use the $_GET array instead

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    You couild also use use a different media type with an alternate stylesheet so that when the user views the page they see it all styled up and when they print it they don't.
    Code:
    <link href="css/stylename.css" rel="stylesheet" type="text/css" />
    <link href="css/stylename_print.css" rel="stylesheet" type="text/css" media="print" />
    Try it on your page now, even IE supports it!

  4. #4
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DJ P@CkMaN
    You couild also use use a different media type with an alternate stylesheet so that when the user views the page they see it all styled up and when they print it they don't.
    Code:
    <link href="css/stylename.css" rel="stylesheet" type="text/css" />
    <link href="css/stylename_print.css" rel="stylesheet" type="text/css" media="print" />
    Try it on your page now, even IE supports it!
    That would add one more request per pageview
    But since it's cached...still little overhead
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point

  5. #5
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    So? It's a better alternative and one more page request never hurt. This way the users doesn't have to click any links, just print the page directly from their browser.

    Certainly worth the sacrifice...

  6. #6
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daijoubu
    That would add one more request per pageview
    But since it's cached...still little overhead
    One request really is not squat, unless you have some very bare pages. And with HTTP 1.1 and keep alive, it really is negligable, especially considering the benefits of doing so.

    Of course, if you are getting charged by the request, you could just put them both in the same stylesheet and use @media rules.

    WWB

  7. #7
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by wwb_99
    Of course, if you are getting charged by the request, you could just put them both in the same stylesheet and use @media rules.
    I was going to say that but @media is depreciated from CSS2 so I held back. Although I believe it is widely supported.

  8. #8
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Daijoubu
    That would add one more request per pageview
    But since it's cached...still little overhead
    as opposed to reloading the entire page (to get the print version), running any queries contained within and generally adding probably twice as much overhead?

  9. #9
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Well someone has a better argument than I did

  10. #10
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile WOW thanks for the replies

    Ok thanks for your replies,

    WOW so which way is it in the end?

    The main reason for the print button is from a User Centered Design point of view, Yes you are internet savvy, but there are still people out there to whom the power switch is an achievement in it self.

    I also was heading that way so that I could send an email link to peeps so they can click and print a page.

    EG. http://www.testing.com?print

  11. #11
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can use javascript for a print button too.

    Code:
    <input type="button" onclick="window.print();" />
    And make an alternate print style sheet like DJP@ described above.

  12. #12
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    arrrrhhhhh

    I am a JavaScript noob,

    So with that would I need to define a function in the head of the xhtml doc? and then call the reload in the body?

    I am going to get around to learning JavaScript sooner or later, probably sooner, as in 5 weeks I have it as a subject LOL

    Thanks for ya help platinum

    "aussie aussie" " ? ? ? "

  13. #13
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nah you won't need a seperate function or anything, just copypaste that code (put it inbetween <form> tags too since it's a form element).

    Off Topic:

    oi oi oi


    and you won't be reloading anything this way.

    so if your html page looks like this:

    Code:
    <div id="header">Images and stuff here</div>
    
    <div id="content">
      <h1>Page Heading</h1>
      <p>some content</p>
    </div>
    
    <div id="footer">more images</div>
    and your two css stylesheets included like above

    Code:
    <link href="css/stylename.css" rel="stylesheet" type="text/css" />
    <link href="css/stylename_print.css" rel="stylesheet" type="text/css" media="print" />
    in your print stylesheet, you can set the header and footer not to print. And also set your content to wrap nicely if needed.

    css (for the print only style sheet):
    Code:
    #header, #footer, .noprint {
      display: hidden;
    }
    if you don't want certain elements to display you can give them the .noprint class. (could also set all images not to print in a similar way by including the img tag).

  14. #14
    SitePoint Addict Mower's Avatar
    Join Date
    Feb 2004
    Location
    Aussie Aussie Aussie
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cool, thanks for the info

    "oi oi oi "


    "Will I ever find my way to GURU?"

  15. #15
    SitePoint Evangelist Daijoubu's Avatar
    Join Date
    Oct 2002
    Location
    Canada QC
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was talking about client side overhead Not all servers leave Keep-Alive on, especialy with Apache and busy websites
    Speed & scalability in mind...
    If you find my reply helpful, fell free to give me a point


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
  •