3
如何访问电子中的DOM元素?
我正在尝试向index.html文件中的按钮添加功能,如下所示:我在按钮元素中index.html <button id="auth-button">Authorize</button> 在main.js应用程序中,我有 require('crash-reporter').start(); console.log("oh yaeh!"); var mainWindow = null; app.on('window-all-closed', function(){ if(process.platform != 'darwin'){ app.quit(); } }); app.on('ready',function(){ mainWindow = new BrowserWindow({width:800, height : 600}); mainWindow.loadUrl('file://' + __dirname + '/index.html'); var authButton = document.getElementById("auth-button"); authButton.addEventListener("click",function(){alert("clicked!");}); mainWindow.openDevTools(); mainWindow.on('closed',function(){ mainWindow = null; }); }); 但是会发生如下错误: Uncaught Exception: ReferenceError: document is …