Javascript - 从输入标签中删除函数

Javascript - Removing a function from input tag

本文关键字:删除 函数 标签 输入 Javascript      更新时间:2023-09-26

我正在尝试恢复过去对我有用的Chrome扩展程序。我真的不了解HTML或Javascript,但我确实对它的工作原理有一个大致的了解。我知道C,所以这有助于理解语法。所以我更改了清单 2 键,以及随之而来的事情,但现在已经停止在一个我无法用谷歌搜索解决的问题上。由于Chrome不再允许内联脚本,因此我不得不将.js脚本链接到.html文件,但不确定如何解决以下错误消息:

拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:"script-src 'self' chrome-extension-resource:"。需要"不安全内联"关键字、哈希 ('sha256-...'( 或随机数 ('nonce-...'( 才能启用内联执行。弹出窗口.html:18

所以有问题的行是

<input type="text" value="" id="home_search_q" size="15" onKeyPress="checkEnter(event, this.value);" autofocus="true" />

.html文件:

<html>
<head>
<title>SearchBox Toolbar</title>
<link rel="stylesheet" type="text/css" href="css/popup.css">
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/popup.js"></script>
</head>
<body>
<form>
<table>
<tr>
<td id="logo">
<div id="logobtn" title="">
<img src="img/logo16.gif" id="logoimg">
</div>
</td>
<td id="query">
<input type="text" value="" id="home_search_q" size="15" onKeyPress="checkEnter(event, this.value);" autofocus="true" />
</td>
</tr>
</table>
</form>
</body>
</html>

我认为问题是该参数是不允许的函数checkEnter,但我不知道如何将其更改为脚本或绕过它。

不要使用内联事件处理程序。

相反,请在外部脚本中调用addEventListener()