0
這裏就是我需要幫助的代碼:我試圖做一個Chrome擴展設置頁,它不工作
if (localStorage.KillTabs == undefined) {
localStorage.KillTabs = 1;
};
if (document.getElementById('killer')) {
if document.getElementById('killer').checked = true {
localStorage.KillTabs = 0;
}
}
if (localStorage.KillTabs == 1) {
console.log("Cannot Clear Tabs");
} else {
console.log("Clearing Tabs...")
//im going to put something here when i know that this works
}
}
<html>
<head>
<script src="options.js"></script>
</head>
<body>
<h1>PrivacyPro Options</h1>
<input type="checkbox" id="killer">
<p class="label">Close All Tabs when done</p>
</body>
</html>
我覺得我做了正確的,但我不確定。我沒有看到任何錯誤。我還希望將設置保存爲當複選框被選中時我希望它保存,所以每次運行擴展時,該設置都會激活,並且只有在複選框未選中時纔會激活。任何幫助都會很好,謝謝!
使用https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-defer和https://developer.chrome.com/extensions/storage –
那些示例令我困惑 – joesmalls23
谷歌瀏覽器示例的字面意思正是你要做的,但正確使用'chrome.storage',而不是'localStorage':https://developer.chrome.com/extensions/optionsV2 – Makyen