這應該是你的腳本:
<body onload="OnLoad()"> //onLoad: run the function OnLoad() when the body is being load
<select id="color" style="width: 5%; height: 10%" size="5">
<option value="white">White</option>
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
<script>
function OnLoad() {
document.getElementById("color").onchange = function() { //Getting the background color from the select
document.body.style.background = this.options[this.selectedIndex].value; //Setting the background color
document.cookie="WebBackgroundColor=" + this.options[this.selectedIndex].value; //Storing in a cookie named: WebBackgroundColor the color that was chosen
}
var color = getCookie("WebBackgroundColor"); //Getting the color stored on the cookie
document.body.style.background = color; //Setting the background color to the same color as stored in the cookie
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
</script>
</body>
要添加此腳本,您需要將身體從改變其他網頁:<body>
到<body onload="OnLoad()">
,你需要添加頁面底部的所有腳本(或標題部分):
<script>
function OnLoad() {
document.getElementById("color").onchange = function() { //Getting the background color from the select
document.body.style.background = this.options[this.selectedIndex].value; //Setting the background color
document.cookie="WebBackgroundColor=" + this.options[this.selectedIndex].value; //Storing in a cookie named: WebBackgroundColor the color that was chosen
}
var color = getCookie("WebBackgroundColor"); //Getting the color stored on the cookie
document.body.style.background = color; //Setting the background color to the same color as stored in the cookie
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}
</script>
您必須爲我們e服務器端語言或cookie。 – 2015-01-26 19:00:48
使用Cookie或服務器端會話進行調查。 – Axel 2015-01-26 19:01:05
只需將它附加到新的url,並讓你的js解析url。 – theonlygusti 2015-01-26 19:01:19