久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Electron 渲染的網頁上調用 JavaScript 函數

How to call a JavaScript function on a web page rendered by Electron?(如何在 Electron 渲染的網頁上調用 JavaScript 函數?)
本文介紹了如何在 Electron 渲染的網頁上調用 JavaScript 函數?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 Twitter 編寫一個包裝器.io/" rel="noreferrer">Electron(以前的 Atom Shell).

I'm trying to write a wrapper for Twitter using Electron (formerly Atom Shell).

我的 main.js 文件(它看起來幾乎與Hello World"的例子,我只是在一個地方改了):

My main.js file (it looks almost identical to the "Hello World" example, I just changed it in one place):

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;
  });
});

我嘗試在 mainWindow.loadUrl() 之后立即調用 alert() 函數,但它沒有執行.

I try to call alert() function right after mainWindow.loadUrl() but it does not execute.

我知道 main.js 文件就像我的應用程序的服務器端,但問題是……如何在頁面上調用 JavaScript 函數?我應該在哪里寫代碼?

I understand that main.js file is like the server side of my app, but the question is... How can I call a JavaScript function on page? Where should I write the code?

例如,我想執行此操作:

For example, I want to perform this:

$(document).ready(function() {
    alert("Hurray!");
});

推薦答案

我已經解決了這個問題.下面是示例代碼:

I have solved the problem. Here's the example code:

...

app.on('ready', function() {

  ...

  mainWindow.webContents.on('did-finish-load', function() {
    mainWindow.webContents.executeJavaScript("alert('Hello There!');");
  });

  ...

});

這篇關于如何在 Electron 渲染的網頁上調用 JavaScript 函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 久久草视频 | 亚洲国产高清高潮精品美女 | 中文字幕一区二区三区精彩视频 | 黄网免费| 国产在线中文字幕 | 免费观看羞羞视频网站 | 久久久久久久久久久高潮一区二区 | 夜夜爆操| 96av麻豆蜜桃一区二区 | 在线观看国产视频 | 亚洲嫩草| 日韩在线综合网 | 精品福利视频一区二区三区 | 欧美成人性生活 | 国产精品视频网站 | 精品国产一区二区三区性色av | 黄色一级电影免费观看 | 国产一区二区精品在线 | 91视频88av| 激情久久网 | 精品乱子伦一区二区三区 | 爱综合 | 久久99精品久久久 | 精品国产一区二区三区久久 | 久久成人高清视频 | 国产激情在线观看视频 | 毛片在线视频 | 亚洲国产一区二区三区四区 | 久久精品视频网站 | 久久亚洲欧美日韩精品专区 | 中文字幕高清一区 | 欧美一级在线观看 | 日韩精品一二三 | 国产av毛片| 欧美福利 | 久久综合久久综合久久 | 欧美一级α片 | 久久久久久高潮国产精品视 | 欧美精品久久久久久久久久 | 亚洲黄色高清视频 | 成人夜晚看av |