简体   繁体   English

如何通过我的所有页面在javascript中加载动态更改的样式

[英]How to load dynamically changed style in javascript through all of my pages

My code so far: http://pastebin.com/KTEF06Kf 到目前为止,我的代码: http : //pastebin.com/KTEF06Kf

I created a simple script that changes the colours of the page. 我创建了一个简单的脚本来更改页面的颜色。 (text background and main logo) When i navigate to another page of my site, if the colours have been changed i want them to be loaded instead of the default colour. (文本背景和主徽标)当我导航到网站的另一页时,如果颜色已更改,则希望加载它们而不是默认颜色。

How would i do this? 我该怎么办? I've tryed creating an onLoad function in the body of the other pages to call a function loadCol() which does the same thing as changeColour but with a preset colour instead of passing in from the box colour that was clicked. 我尝试在其他页面的主体中创建onLoad函数来调用函数loadCol(),该函数与changeColour相同,但具有预设颜色,而不是从单击的框颜色中传入。

Any clues of how i can acheive this. 关于我如何能做到这一点的任何线索。 (Sorry if its poorly explained) (很抱歉,如果解释不清)

When selecting something on one page, and making it persistent on all other pages, you'll need to store that value somewhere, as HTML in stateless and has no idea what was selected on the first page. 在一个页面上选择某项并将其保留在所有其他页面上时,您需要将该值存储在某个位置,因为HTML是无状态的,并且不知道在第一页上选择了什么。

You can use cookies or local storage, or both, MDN has a polyfill for local storage that falls back to cookies. 您可以使用Cookie或本地存储,或同时使用两者, MDN具有用于本地存储的Polyfill,可使用Cookie。

You could also just pass the value in the links to the other pages with a hash or querystring: 您也可以使用散列或查询字符串在指向其他页面的链接中传递值:

mysite.com/page2?color=blue

mysite.com/page2#color=blue

Where you use javascript to change the anchors when a color is selected. 选择颜色时使用javascript更改锚点的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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