好吧,我有一个打包的应用程序,这个应用程序包含index.html和其他页面.. index.html 包含链接到其他页面的按钮..
问题是按钮不起作用!当我点击按钮时......什么也没有发生。
这是主要文件:
{
"name": "TextTools",
"description": "Simple tools for Text.",
"version": "0.0.0.1",
"manifest_version": 2,
"icons": {
"128": "logo.png"
},
"app": {
"launch": {
"local_path": "index.html"
}
}
}
这是 Index.html 正文标记:
<body>
<center><div id="container">
<div><input id="btn1" type="button" value="Letters Counter" class="btn1"
onclick="location.href='LettersCounter/LengthCalculator.html';"></div>
<div><input id="btn2" type="button" value="Case Converter" class="btn2"
onclick="location.href='CaseConverter/CaseConverter.html';"/></input></div>
<div><input type="button" value="Text Capitalizer" class="btn3"
onclick="location.href='CapitalizeText/CapitalizeText.html';" /></div>
<div><input type="button" value="Words Counter" class="btn4"
onclick="location.href='WordsCounter/WordsCounter.html';" /></div>
<div><input type="button" value="QR-Generator" class="btn5"
onclick="location.href='QRcode/index.html';" /></div>
</div></center>
<div id="foot" >
<p style="color:#B8B8B8; margin-left:10px; margin:10px; font-family: Gill Sans, sans-serif; font-size : 14px; "></p>
</div>
</body>
我知道这很简单,但我是新人:)
最佳答案
问题
您正在使用内联javascript, Content Security Policy for Chrome Apps 不允许使用该js。 :
<小时/>The content security policy for Chrome Apps restricts you from doing the following:
- You can’t use inline scripting in your Chrome App pages. The restriction bans both blocks and event handlers (
<button onclick="...">
).[...]
解决方案
使用外部.js
注册监听器的文件。例如:
/* Instead of... */
<input id="btn1" type="button" onclick="..." ... />
/* ...change HTML to... */
<input id="btn1" type="button" ... />
...
<script type="text/javascript" src="myScript.js"></script>
/* ...and in `myScript.js` add... */
document.getElenentById("btn1").addEventListener("click", function() {
...
});
关于javascript - Chrome 应用程序中的按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20012821/