![](/img/trans.png)
[英]How to change the content of a div on one html page with the contents of a div from another page using javascript?
[英]How to change CSS of one page from another page using JavaScript
我有兩個網頁:
pageone.html
和pagetwo.html
在pageone.html
,有一個ID為change-color
按鈕當您單擊該按鈕時, pagetwo.html
的背景顏色應該變為綠色。 但那並沒有發生。 有人能幫我嗎?
function changeColor() { //code var pageTwo = 'pagetwo.html'; pageTwo.style.backgroundColor = "green"; }
<button type="button" id="change-color" onclick="changeColor">Change Background Color</button>
您可以嘗試如下
在pageone.html中
window.localStorage.setItem("bg", "")
function changeColor() {
window.localStorage.setItem("bg", "green");
}
在pagetwo.html中
<script>
var bg = window.localStorage.getItem("bg");
if(typeof bg!= 'undefined' && bg != ""){
//Set your background using bg variable
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.