Electron中提示:Refused to execute inline event handler because it violates

场景

在Electron中点击index.html中的button按钮时想要其触发renderer.js的方法。

在index.html中

<button onclick="getProcessInfo()">查看Process信息</button>

在js中

function getProcessInfo()
{
    console.log("getProcessInfo************************");
}

然后提示:

Refused to execute inline event handler because it violates

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

修改为通过在html中给button添加id,然后在js中通过getElementById获取

<button id="buttonProcess" >查看Process信息</button>

然后在js中

var btn=document.getElementById('buttonProcess');
    
btn.onclick=getProcessInfo;

 function getProcessInfo()
{
    console.log("getProcessInfo**********************");

}

效果

原文地址:https://www.cnblogs.com/badaoliumangqizhi/p/12993112.html