简体   繁体   中英

Accessing local storage in CSS when using a chrome extension?

Is there a way to access local storage from a chrome extension option file with CSS? Can I use javascript to set a variable that I can access in CSS, or is local storage a javascript exclusive thing? If it is, is there a way I can set options for CSS without local storage?

localStorage is only accessible via JS. You can not make dynamic queries in CSS files as they are for the most part totally static (this has changed some with new CSS props such as variables, etc.), but you still cannot make calls to data that is not an imported resource.

The only way you can set options dynamically in CSS is by changing the state of the HTML (changing class names, etc.), or by adding stylesheet rules dynamically via JS, or straightforward style manipulating via JS, element.style.prop = 'prop' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM