【发布时间】:2018-07-05 04:10:55
【问题描述】:
我想让自己成为一个密码管理器,仅供私人使用。我知道这不安全,但我不在乎。
我在 ui/default_popup 文件中制作密码列表时遇到问题。我制作了一个带有滚动条的 div,我想要一些 javascript 在这个 div 中添加一些 div,并使用我的密码,但我似乎无法添加项目。
现在我已经尝试设置它,所以有一个按钮,当我按下它时,它会在我的 div 中添加一个 div。如果我在浏览器中打开它可以正常工作,但如果我将其用作我的扩展程序,它将无法正常工作,当我单击按钮时根本没有任何反应。
Manifest.json:
{
"name": "Password Manager",
"manifest_version": 2,
"version": "2",
"version_name": "alpha 1",
"description": "Alpha for my password manager project",
"permissions": [
"activeTab",
"tabs",
"http://*/*", "https://*/*"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "main.html"
}
}
默认弹出窗口:
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
<meta charset="utf-8">
<script>
function test() {
var element = document.createElement("div");
element.appendChild(document.createTextNode('The man who mistook his wife for a hat'));
document.getElementById('pswcontainer').appendChild(element);
}
</script>
</head>
<body>
<div class="bluebox"><h1 style="color : white;">Password Manager</h1></div>
<div id="maindiv">
<div id="passInBox">
<h3 style="margin-top : 0px; width : 100%; text-align : center;">Please input your universal password:</h3>
<input style="width : 100%;" type="password" id="pswIn">
</div>
<div id="pswcontainer">
<div class="psw">
<button onclick="test()"
</div>
</div>
</div>
<div class="bluebox" style="position: absolute; bottom : 10px; width : 485px;"></div>
</body>
</html>
css:
html {
width : 500px;
height : 590px;
padding-left: 5px;
padding-right: 5px;
padding-top: 5px;
padding-bottom: 5px;
font-family: Arial, Helvetica, sans-serif;
}
.bluebox {
width : 100%;
height : 50px;
background-color: #3b9ddd;
border-radius: 7px;
padding-bottom: 1px;
display: flex;
align-items: center;
justify-content: center;
margin-top: 3px;
margin-bottom: 3px;
}
.psw {
height : 60px;
width : 440px;
margin : 5px;
border : 1px solid black;
}
#passInBox {
margin: auto;
width: 60%;
border: 1px solid grey;
padding: 10px;
}
#maindiv {
padding : 3px;
height : 100%;
}
#pswcontainer {
margin-left: 3px;
margin-right: 3px;
margin-bottom: 3px;
margin-top: 5px;
border-radius: 2px;
width: 467px;
height: 373px;
overflow-y : scroll;
border : 2px solid black;
}
【问题讨论】:
-
扩展中禁止运行内联JS。将您的 JS 代码移动到外部文件。
标签: javascript html google-chrome google-chrome-extension