Dynamically loading an external CSS file using JavaScript -


possible duplicate:
dynamically loading external css file

i'm trying create dynamic page using external .css pages page color changed. below code. when click href, not getting output. can please tell what's problem in code? suggestions or ideas please.

<script language="javascript"> function loadjscssfile(filename, filetype) {     if (filetype=="css")     {          var fileref=document.createelement("link")         fileref.setattribute("rel", "stylesheet")         fileref.setattribute("type", "text/css")         fileref.setattribute("href", filename)     }     if (typeof fileref!="undefined")         document.getelementsbytagname("head")[0].appendchild(fileref) }  loadjscssfile("mystyle.css", "css")  </script> <a href="javascript:loadjscssfile('oldstyle.css','css')">load "oldstyle.css"</a>  

i have modified code below. still i'm facing problem in getting output. no result. can please me out?

<head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" type="text/css" href="css/newstyle.css" /> <script language="javascript" type="text/javascript"> function loadjscssfile(filename, filetype) {     if (filetype=="css")      {         var fileref = document.createelement("link");         fileref.rel = "stylesheet";         fileref.type = "text/css";         fileref.href = "filename";         document.getelementsbytagname("head")[0].appendchild(fileref)     } } loadjscssfile("oldstyle.css", "css")  </script> <a href="javascript:loadjscssfile('oldstyle.css','css')">load "oldstyle.css"</a>  </head> 

if want switch style of site on instance (click), without refreshing page, need use js , cookies both.

may below link helpful:

http://www.dynamicdrive.com/dynamicindex9/stylesheetswitcher.htm


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -