我正在尝试使用Electron(以前的 Atom Shell)为Twitter编写一个包装器。
我的main.js
文件(它看起来几乎与“ Hello World ”示例相同,我只是在一处进行了更改):
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
// Report crashes to our server.
require('crash-reporter').start();
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit();
});
// This method will be called when atom-shell has done everything
// initialization and ready for creating browser windows.
app.on('ready', function() {
// Create the browser window.
mainWindow = new BrowserWindow ({'width':1000,'height':600});
// and load the index.html of the app.
mainWindow.loadUrl('https://twitter.com');
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
});
我尝试在alert()
之后立即调用函数,mainWindow.loadUrl()
但它没有执行。
我知道该main.js
文件就像我的应用程序的服务器端,但问题是......如何在页面上调用 JavaScript 函数?我应该在哪里写代码?
例如,我想执行此操作:
$(document).ready(function() {
alert("Hurray!");
});