Forum Moderators: not2easy

Message Too Old, No Replies

CSS Selector from link?

Custom CSS For each user.

         

awarlock

10:19 am on Sep 15, 2003 (gmt 0)



Is it possible to have a link to a page that will load a custom CSS file for the next page? I know you can have a CSS selector on a certain page, but i want the CSS to link from the previous page.

For example:
If someone comes in from FRONT1.htm I want MAIN.htm to have red.css
If someone comes in from FRONT2.htm i want MAIN.htm to have blue.css

Any relevant links on this subject, course code..etc
would be very helpful. thank you

MonkeeSage

3:21 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To click a link on page 1 and change the stylesheet on the page that loads (page 2), you can do...

File1.htm...

...
<script type="text/javascript">
<!--
function loadCSS(file, css) {
window.location.href = file + '?' + css;
}
//-->
</script>
</head>
...
<a href="File2.htm" onclick="loadCSS(this.href, 'blue.css'); return false;">Blue</a>
<a href="File2.htm" onclick="loadCSS(this.href, 'red.css'); return false;">Red</a>

File2.htm...

...
<script type="text/javascript">
<!--
if (window.location.search) {
var css = window.location.search.substring(1);
document.write("<link type=\"text/css\" rel=\"stylesheet\" href='" + css + "'/>");
}
//-->
</script>
</head>
...
<div>
This is some text...
</div>

--------

To change the stylesheet on page 2 based on where a person came from, do something like...

File2.htm...

...
<script type="text/javascript">
<!--
if (document.referrer) {
var css = null;
if (document.referrer.search(/File1\.htm/i)!= -1) {
css = "red.css";
}
if (document.referrer.search(/File3\.htm/i)!= -1) {
css = "blue.css";
}
document.write("<link type=\"text/css\" rel=\"stylesheet\" href='" + css + "'/>");
}
//-->
</script>
</head>
...
<div>
This is some text...
</div>

HTH
Jordan