I’m not familiar with using the DOM to do that. Is that something that I would be able to pass on to a new page via the URL though? Or would it only be changing the existing page by swapping the style sheet? If the latter, I’ve already been able to do with with a style switcher javascript, but it’s not what the client wants. If it’s the former, how do I pass the value to the linked page?
I’ve been experimenting with the php to try and narrow down the problem. I’ve made the following test page:
http://www.orionvisuals.com/wip/harryjenkins/phptest.php
The file has the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Harry Jenkins MP</title>
<script src="http://www.orionvisuals.com/wip/harryjenkins/styleswitcher.js" type="text/javascript" language="Javascript"></script>
<?php
if($style == 'printFriendly') $stylesheet = 'assets/css/hjprint.css';
else $stylesheet = 'assets/css/hjmain.css';
echo '<link rel="Stylesheet" href="'. $stylesheet .'" type="text/css" />';
?>
<body>
<p>testing</p>
<p><a href="?style=printFriendly">Print view</a></p>
<div id="printhide"><p>Should be hidden in printer view</p></div>
</body>
</html>
I’m not having a problem in this example with the php failing to replace the style sheet. When looking at the generated code, there’s no php to be seen, only a style sheet link in its place. However the swapping isn’t working. If you click on the link in the page, and then look at the new page’s source, you will see it’s using the default css - hjmain.css - not the printer version - hjprint.css -. If I reverse the two in the php and put the main css in the line "if($style == ’printFriendly’) $stylesheet = ’ then the printer version of the style is loaded, and when the link clicked - it stays the same. It seems that the SECOND style sheet referenced in the php is used, regardless of the arguments appended to the url linking to it.
So this doesn’t shed any light on why the php isn’t working on the main site, but adds another new problem into the mix! This is getting frustrating...