1

Currently working on a web form that allows a user to manually edit specific CSS rules (through jquery).

What I need to do is persist those specific (around 4-5) rules for later use.

By later use, I mean that users/customers will visit a website that has an "AccessID" in the URL.

Based on the AccessID, the CSS rules should differ based on what was chosen by the page designer.

My idea is to take the 4-5 values that make up the CSS rules and store them into the database along with the AccessID.

When the specific website URL is accessed, query those CSS rules and load them into the .css file.

Is this at all possible? Is it a risky process to attempt? Is there a better way?

The CSS rules have to persist as long as a user continues to have an account and run their specific website with AccessID.

I've read some SO questions regarding cookies, but I'm not sure how that plays a factor in this situation.

Please let me know if you have any suggestions. Thank you.

Tab Alleman
  • 31,483
  • 7
  • 36
  • 52
terbubbs
  • 1,512
  • 2
  • 25
  • 48
  • 2
    Have you given it a try , any code? I think its possible,but on extracting from db it would be better to apply the CSS using js/jquery rather than loading into a CSS file. – Varun Jun 24 '15 at 18:43
  • you can use Local Storage although this method is used to cache whole css file for speed purposes as far as i know. But because Local Storage can be cleared through the browsers settings you may need a fallback routine to say if the users CSS doesnt exist in LS then fetch it from the database. – Tasos Jun 24 '15 at 19:24
  • @Varun i haven't tried yet, but I had a concept worked out. I agree that it would be better to apply CSS using script. – terbubbs Jun 24 '15 at 23:49

1 Answers1

2

You could create the access id in the form of the styles you want to persist such as http://url.com?style1=value&style2=value&style3=value

Then when people visit via that url you can get the url string parameters Get url parameter jquery Or How to Get Query String Values In js

...and then append those styles on page load.

$('head').append('<style type="text/css">body {style1:value;}</style>');
Community
  • 1
  • 1
c01gat3
  • 597
  • 3
  • 18
  • I like this idea but unfortunately the AccessID is determined by other means. Users will actually have to type in... www.website.com/module?accessid="AND THEN A SLIGHTLY LONG ID" – terbubbs Jun 24 '15 at 23:50