【发布时间】:2015-11-19 14:19:52
【问题描述】:
所以我想保存用户选择的主题,因此我选择弹出窗口来显示它们。 每次我关闭标签页(3 次后)或退出 chrome 时,它都会忘记我的选择。
我的选项.html
<html>
<head>
<script src="options.js"></script>
<link href='https://fonts.googleapis.com/css?family=Raleway:400,300,200,100' rel='stylesheet' type='text/css'>
</head>
<body>
<center>
<label class="paylabel" for="cardtype">Theme:</label>
<select id="cardtype" name="cards">
<option value="selectcard">--- Please select ---</option>
<option value="op1">Theme 1</option>
<option value="op2">Theme 2</option>
</select>
</center>
<br />
<br />
<br />
<br />
<h1 style="font-family:Raleway; font-weight:200; float:left">Theme 1</h1>
<h1 style="font-family:Raleway; font-weight:200; float:Right">Theme 2</h1>
<br />
<br />
<br />
<br />
<br />
<br />
<img src = "screen2.png"; alt="" style="float:left"/>
<img src = "screen1.png"; alt="" style="float:right"/>
</body>
</html>
Options.js:
time=setInterval(function(){
var ddl = document.getElementById("cardtype");
var selectedValue = ddl.options[ddl.selectedIndex].value;
localStorage["inputText"] = selectedValue;
var myvar = localStorage["inputText"];
if (myvar == "op2")
{
chrome.browserAction.setPopup({
popup: 'popup.html'
});
}
else{
chrome.browserAction.setPopup({
popup: 'popup2.html'
});
}
},1000);
谢谢。
【问题讨论】:
-
不要使用
setInterval。使用正确的方法,如ddl.onchange = function(e) { ....... }; -
好的,这不起作用我还需要做什么?谢谢
-
您需要尝试实现它并在出现问题时使用the debugger。
-
我真的很抱歉,但我似乎能弄明白。除非我使用 serInterval,否则我的弹出窗口不会改变。可以帮忙解答一下吗?
标签: javascript google-chrome google-chrome-extension local-storage