我想做一个简单的扩展来节省简短的粘贴。我只是在将粘贴放入表单中会更改表单正下方的 div 的innerHTML;不过,这不是我遇到的问题。
我的问题是,当我尝试使用 Chrome 扩展中的代码时,它无法更改表单下 div 的innerHTML,但是当我在浏览器上简单地运行代码时,代码会按照我的意图执行正如我所期望的那样去做和工作。
是我的代码有问题吗?是否需要使用 Chrome 扩展执行任何额外操作才能使我的 JavaScript 代码正常工作?任何事情都有帮助!
谢谢
代码: HTML:
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width: 357px;
overflow: hidden;
height: 700px;
background-color: #F7F8E0;
}
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
-->
<!--<script src="popup.js"></script>-->
<script src="pastebook.js"></script>
</head>
<body>
<form name="newpaste">
New Paste: <input type="text" name="pasteform" value="Paste your new Paste">
<button type="button" onclick="newPaste()">Save Paste</button>
</form>
<div id="bookofpastes"></div>
</body>
</html>
Javascript:
function newPaste() {
newpaste=document.newpaste.pasteform.value;
document.getElementById("bookofpastes").innerHTML=newpaste;
}
如果有帮助的话,我的manifest.json文件:
{
"manifest_version": 2,
"name": "pastebook",
"description": "Keep a list of all your pastes here",
"version": "0.1",
"browser_action": {
"default_icon": "book2.png",
"default_popup": "pastebook.html"
}
}
最佳答案
显然你不能在 list 版本 2 中使用内联 javascript 代码:
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-apps/BEAGuCsX4pU
关于javascript - HTML/JS 代码可以在普通浏览器 View 中运行,但无法作为 Chrome 扩展运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23462756/