dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: Create text only CSS (like print friendly but text displayed on browser)

  1. #1
    Join Date
    Oct 2007
    Posts
    161

    Create text only CSS (like print friendly but text displayed on browser)

    Hi

    I need to find a way to create a 'click here for text only' version of my webpage(s) and I'm assuming I can do this in a similar way to 'print friendly' stylesheets... so that when the 'text only' link is clicked the same page is displayed on either the same or a fresh browser window, but using a text only stylesheet - to remove all the unnecessary elements of the page.

    Does anyone know a way to this? I've done it for print - but this automatically selects the stylesheet based on the media (so click on print and the browser applys the print.css styesheet).

    Cheers for any help
    Lou

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654

  3. #3
    Join Date
    Dec 2005
    Posts
    2,984
    Try using javascript to switch the media type of the stylesheets:

    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
     <head>
      <title>Your Site</title>
      <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
      <meta http-equiv="Content-Language" content="en-us" />
    
       <link rel="stylesheet" type="text/css" media="screen" href="web.css" />
       <link rel="stylesheet" type="text/css" media="print" href="text.css" />
    
    <script type="text/javascript">
    /* <![CDATA[ */
    
     function textOnly() {
      for(i=0;i<document.styleSheets.length;i++) {
       if(document.styleSheets[i].media == "screen") {
        document.styleSheets[i].media = "print";
       } else {
        document.styleSheets[i].media = "screen";
       }
      }
     }
    
    /* ]]> */
    </script>
    
     </head>
     <body>
       <a href="#" onclick="textOnly();">Toggle Text Only</a>
     </body>
    </html>
    Last edited by aj_nsc; 03-27-2008 at 10:12 AM.

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