Question: Stylesheet switching with PHP possible?

This is a discussion on "Question: Stylesheet switching with PHP possible?" within the PHP Forum section. This forum, and the thread "Question: Stylesheet switching with PHP possible? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Sep 25th, 2004, 03:00
Junior Member
Join Date: Jul 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Question: Stylesheet switching with PHP possible?

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!

  #2 (permalink)  
Old Sep 25th, 2004, 03:29
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
There's no need to actually do that. You can define a web version and a print version of the same stylesheet and the browser will use the correct one...

http://www.meyerweb.com/eric/article...ev/200001.html

If you still really wanted to do your css switching, then merely change the file that's specified in the href of your LINK tag depending on a condition such as a GET variable. eg:
If you have a page.php?printview=yes
Then change the file here:
Code: Select all
<LINK rel="stylesheet" type"text/css"
     href="print.css" media="print">
  #3 (permalink)  
Old Sep 25th, 2004, 04:19
Junior Member
Join Date: Jul 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks to everybody who attempted to help. I got help from another site which gave this:

Code: Select all
<!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>



Hello!
</p>
</body>
</html>
Simple? Yes, but I wanted more! Rather than a button which only linked to a printable version, I wanted to use a link back! Dropdowns work:

Code: Select all
<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 renders a dropdown which works much better! Less clutter than radio buttons as well!

Thank you everybody!

Especially Sirkent! I knew the media attribute was the answer, but I didn't know how to apply it. Thanks for the article. It showed me that it is only displayed when printed.
Closed Thread

Tags
question, stylesheet, switching, php, possible

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Switching Host Jack Franklin Hosting & Domains 17 Mar 16th, 2008 22:14
switching backgound image pahvi67 JavaScript Forum 4 Jan 16th, 2008 13:27
switching between style sheets cwjones Web Page Design 4 Jul 4th, 2007 17:06
Switching from ASP to ASP.net jsa ASP.NET Forum 1 Nov 27th, 2006 17:26
Switching images in cells... Kingcobra220 JavaScript Forum 2 Sep 3rd, 2006 22:33


All times are GMT. The time now is 02:13.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43