|
|
|
|
Joined: Dec 2003
Posts: 13
Junior Member
|
|
Junior Member
Joined: Dec 2003
Posts: 13 |
Im using this code for a style changer function setActiveStyleSheet(title) { var i, a, main; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { a.disabled = true; if(a.getAttribute("title") == title) a.disabled = false; } } }
function getActiveStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); } return null; }
function getPreferredStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) return a.getAttribute("title"); } return null; }
function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }
function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }
window.onload = function(e) { var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); }
window.onunload = function(e) { var title = getActiveStyleSheet(); createCookie("style", title, 365); }
var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title);In my head section i have this <link rel="stylesheet" type="text/css" href="tcw.css" title="default"/> <link rel="alternate stylesheet" type="text/css" href="tcw1.css" title="tcw1"/> Im supposed to be using HREF's to make this work. <a href="#" onclick="setActiveStyleSheet('default'); return false;">change style to default</a><a href="#" onclick="setActiveStyleSheet('tcw1'); return false;">change style to paul</a> and it does work. However, how do i convert these to use DROPDOWN's instead of hrefs?
|
|
|
|
|
Joined: May 2000
Posts: 1,356
Addict
|
|
Addict
Joined: May 2000
Posts: 1,356 |
try this: <script> function css_drop (select) { var value = select.options[select.selectedIndex].value; if(value) { setActiveStyleSheet(value); return false; } select.selectedIndex = 0; } </script>
<form> <select name="css_drops" onchange="css_drop(this)"> <option>Select a style</option> <option value="default">change style to default</option> <option value="tcw1" >change style to paul</option> </select> </form>
|
|
|
|
|
Joined: Dec 2003
Posts: 13
Junior Member
|
|
Junior Member
Joined: Dec 2003
Posts: 13 |
|
|
|
|
|
Joined: Dec 2003
Posts: 13
Junior Member
|
|
Junior Member
Joined: Dec 2003
Posts: 13 |
Is there a way to have a go button or something, because i need it to auto refresh the page..
|
|
|
|
|
Joined: Jan 2000
Posts: 5,073
Admin Emeritus
|
|
Admin Emeritus
Joined: Jan 2000
Posts: 5,073 |
Oh, that's going to be a problem...
When the page reloads, it will default back to whatever the original stylesheet was, forgetting the user choice.
In order to remember the user stylesheet pref, you'd probably want to set a cookie, then use a document.write to set the default stylesheet based on that cookie. Of course, you don't want to store the stylesheet name with the cookie, just an identifier to associate with the stylesheet, as to avoid forged cookies causing problems...
Confused? %)
UBB.classic: Love it or hate it, it was mine.
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 21,080
Joined: March 2000
|
|
|
Forums63
Topics37,583
Posts293,955
Members13,824
| |
Most Online151,614 Nov 14th, 2025
|
|
Currently Online 701
Topics Created 0
Posts Made 0
Users Online 0
Birthdays 13
|
|
|
|
|
|