...

View Full Version : Style sheet switch possible?



gohankid77
09-25-2004, 04:45 AM
Hello everybody. I recently started learning PHP, and I was simply wondering if there was a way to use PHP to "switch" style sheets for a page. Basically, it would look like any other page with a link to a printable version. The difference would be that I wouldn't create a completely new page, but simply "switch" style sheets from the screen version to a printable version. Is this possible?

Thanks from a PHP newbie in advance!

dniwebdesign
09-25-2004, 04:53 AM
sure... you can use something like below:



$print=$_GET["print"];

if($print=="true")
{
echo "<LINK rel=stylesheet type='text/css' href='css/printable.css'>";
}
else
{
echo "<LINK rel=stylesheet type='text/css' href='css/normal.css'>";
}


Say you have the URL... http://www.nsjhl.com/index.php
To switch style sheets use http://www.nsjhl.com/index.php?print=true

gohankid77
09-25-2004, 04:59 AM
Thanks a lot! Going to test right now!

// Edit

Forgive me, but can you show me how I would apply that in a form? I can't seem to get it to work.

Thank you again.

// Edit

I got it to work:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-us">
<head>
<title>Testing!</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<?php
$print=$_GET["print"];

if($print=="true")
{
echo "<link rel='stylesheet' type='text/css' href='print.css'>";
}
else
{
echo "<link rel='stylesheet' type='text/css' href='normal.css'>";
}
?>
</head>
<body>
<form action="test.php" method="GET">
<input type="hidden" name="print" id="print" value="true">
<input type="submit" value="Printable version">
</form>
<p>
Hello!
</p>
</body>
</html>


Thank you so much! Now, to get it to work using <select> menus!

gohankid77
09-25-2004, 05:38 AM
<form action="test.php" method="GET">
<select name="print">
<option value="true">Printable version</option>
<option value="false">Normal version</option>
</select>
<input type="submit" value="Go!">
</form>


That is the modified <select> code. Just so a user can select their own version! LOL

Thank you, dniwebdesign! :cool:

Nightfire
09-25-2004, 01:14 PM
You don't need to do this ya know? You can do it with html

Have both stylesheets linked up in your header like this

<link rel="stylesheet" media="print" type="text/css" href="print.css">
<link rel="stylesheet" type="text/css" href="normal.css">

gohankid77
09-25-2004, 05:01 PM
Yeah... I found out from another site :) I just wanted any users to see a printable version.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum