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**********************");

}

效果

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章