0

I have a stylepage which should allow the user to change the style of not just the webpage but the whole website. To do this I was planning on inserting rules to my main stylesheet whenever the user selects a property. I have props to call my stylesheet by its id and then insert the rule. Anyone has an idea how to go about it? My stylesheets id is myStylesheet... To be complete I don't want to change my stylesheet or add a new one. If you do that it only works on that one page, I want my whole site to be changed. The function in javascript should look something like this:

     funcion bg1 {
     var sheet = document.styleSheets[myStylesheet];
     sheet.insertRule(
          "body{    background-image: url(../afbeeldingen/bg1.jpg);
          background-position: center;
          background-repeat: repeat;
          background-size:100%;}"
     ;}

but I can't get it to work

Rimil Dey
  • 827
  • 2
  • 13
  • 33
ufotje
  • 11
  • 6
  • This is a duplicate of http://stackoverflow.com/questions/19844545/replacing-css-file-on-the-fly-and-apply-the-new-style-to-the-page – Phaze Phusion Jan 28 '17 at 15:18
  • You can only do this by server side codes, But it very strange thing to do. Say what you exactly want it will have better solutions. – Farzin Kanzi Jan 28 '17 at 15:41
  • @Phaze Phusion: No it's not, he wants to replace his stylesheet with a other stylesheet, while I want to add rules to one and the same... – ufotje Jan 28 '17 at 15:59
  • @Farzin Kanzi. I know you can do it with jquery or javascript. In javascript it would look something like this: funcion bg1{ var sheet = document.styleSheets[myStylesheet]; sheet.insertRule("body{ background-image: url(../afbeeldingen/bg1.jpg);background-position: center; background-repeat: repeat; background-size:100%;}"; } but I can't get it to work... – ufotje Jan 28 '17 at 16:01
  • @ufotje because you're not reading well https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule – Roljhon Jan 28 '17 at 16:33
  • Possible duplicate of [Replacing css file on the fly (and apply the new style to the page)](http://stackoverflow.com/questions/19844545/replacing-css-file-on-the-fly-and-apply-the-new-style-to-the-page) – user692942 Jan 31 '17 at 00:20

0 Answers0