久久久久久久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 服務器時的歡迎消息)
主站蜘蛛池模板: 亚洲成人免费观看 | 日韩久久久久久 | 成人一区二区三区 | 中文字幕一区二区三区四区五区 | 中文字幕成人 | 伊人伊成久久人综合网站 | 日本三级电影在线观看视频 | 日韩在线免费播放 | 欧美无乱码久久久免费午夜一区 | 久草网址 | 日韩综合在线视频 | 91高清视频在线观看 | 少妇特黄a一区二区三区88av | 午夜精品导航 | 亚洲精品女人久久久 | 日韩中文字幕免费 | 国产日韩欧美在线 | 日韩一区二区三区在线观看 | 欧美视频在线看 | 久久新| 国产精品久久久久久久7777 | 成人九色 | 久久小视频 | 亚洲精品自在在线观看 | 日本黄色大片免费 | 日韩av福利在线观看 | 亚洲福利| 狠狠干网| 欧美一区二区三区精品免费 | 精品99久久久久久 | 精品精品| 欧美福利视频一区 | 人人cao| 一区在线观看 | 高清国产午夜精品久久久久久 | 精品国产欧美一区二区三区成人 | 国产精品久久久久aaaa樱花 | 久久免费高清 | 亚洲国产一区二区三区 | 亚洲视频在线免费观看 | 久久精品国产久精国产 |