【发布时间】:2014-03-09 03:41:36
【问题描述】:
首先,我的英语很烂,希望你能明白一切..
我在谷歌浏览器上创建了一个小扩展。 基本上它是这样做的:
- 当您点击扩展的图标时,它会显示一个表单 (popup.html)
- 当您点击提交按钮时,它会创建一个新的 cookie (popup.js)
popup.html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" target="_blank" rel="stylesheet">
<style>
body {
overflow-x: hidden;
background-color: white;
width: 170px !important;
height: 200px;
}
</style>
<script src="popup.js" langage="javascript"> </script>
</head>
<body>
<center>
<form action="online.html"><input id="alertButton" type="submit" value="submit"></input>
</form>
</center>
</body>
</html>
popup.js
function myAlert()
{
chrome.cookies.set({url : "testing.com", domain : "www.testing.com", name : "name1", value: "value1", path : "/"}) ;
alert("after");
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('alertButton').addEventListener('click', myAlert);
});
所以是的.... 它根本不会创建任何 cookie。 我不明白,我已经尝试解决这个问题好几个小时了。 alert("after") 显示良好。
我需要帮助,谢谢你的帮助!
【问题讨论】:
-
好的,我找到了解决方案,我认为是语法错误: popup.js function myAlert() { if ( getCookie() == true ) return else chrome.cookies .set({“url”:“testing.com”,“域”:“www.testing.com”,“名称”:“名称1”,“值”:“值1”,“路径”:“/”} );警报(“之后”); }
-
我从主题中删除了“已解决”标签,这不是 Stack Overflow 的工作方式。添加对此问题的答案,然后将其标记为已接受。赞成其他答案也是礼貌的。
标签: javascript cookies google-chrome-extension popup