Click to See Complete Forum and Search --> : Create text only CSS (like print friendly but text displayed on browser)


LouPhi
03-27-2008, 09:55 AM
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

Fang
03-27-2008, 10:07 AM
Style switcher (http://www.alistapart.com/stories/n4switch/)

aj_nsc
03-27-2008, 10:07 AM
Try using javascript to switch the media type of the stylesheets:



<!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>