好吧,我有一个包装的应用程序,这个应用程序包含index.html和其他页面.. index.html包含链接到其他页面的按钮..

问题是按钮不起作用!!当我点击按钮时..没有任何事情发生。

这是mainifest文件:

{
  "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标签:

<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 Chrome Apps的内容安全策略

Chrome应用程序的内容安全策略限制您执行以下操作:

  • 您无法在Chrome App页面中使用内联脚本。限制禁止块和事件处理程序(<button onclick="...">)。

[...]


解决方案

使用注册侦听器的外部生成acodeTagcode文件。例如:

/* 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() {
    ...
});
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top