< li > < button onclick = " openNewWindow() " > new BrowserWindow </ button > </ li > < li > < button onclick = " windowOpen() " > window.open </ button > </ li > < li > <button οnclick="οnclick="changePage('./pages/openWindow/openWindowIndex.html')"">切换页面 </ button > </ li >

切换页面 和 打开窗口的方法

  1. window.location.href 切换窗口内容
  2. window.open 打开新的窗口
  3. new BrowserWindow 打开新的窗口
const path = require('path')
// 当前页面做切换
function changePage (pageUrl) {
    window.location.href = pageUrl
// 使用 window.open 打开一个新的窗口
function windowOpen () {
  // window.open 来创建一个新的窗口时候,将会创建一个 BrowserWindow 的实例,并且将返回一个标识,这个界面通过标识来对这个新的窗口进行有限的控制.
  // window.open(url[, frameName][, features])
  // url String
  // frameName String (可选)
  // features String (可选)
  let url = path.join("file://",__dirname,"./pages/introduce.html");
  let winObj = window.open(url)
  console.log("winObj : " + winObj)
// 创建一个 BrowserWindow 对象,打开一个新的窗口
function openNewWindow() {
  // __dirname 代表的是html文件的路径,不是js的路径;E:\gitcode\electron-study\src
  console.log(__dirname);
  const modalPath = path.join("file://",__dirname,"./pages/introduce.html");
  let win = new BrowserWindow({ width: 400, height: 275 });
  win.on("resize", updateReply);
  win.on("move", updateReply);
  win.on("close", function() {
    win = null;
  });
  win.loadURL(modalPath);
  win.show();
  function updateReply() {
    const manageWindowBtn = document.getElementById("infoContainer");
    const message = `Size: ${win.getSize()} Position: ${win.getPosition()}`;
    manageWindowBtn.innerHTML = message;
 

如果要使用 require(‘path’), 则需要开启nodejs环境,否则无法使用

打开新窗口需要 —— 开启nodejs环境

const { app, BrowserWindow, BrowserView, globalShortcut } = require('electron')
var mainWindow = null // 声明要打开的主窗口
app.on('ready', () => {
  // 设置窗口的高度和宽度
  mainWindow = new BrowserWindow({
    width: 800,
    height: 800,
    frame: false, // 是否有边框
    webPreferences: {
      nodeIntegration: true, // 设置开启nodejs环境
      enableRemoteModule: true // enableRemoteModule保证renderer.js可以可以正常require('electron').remote,此选项默认关闭且网上很多资料没有提到
  // 窗口加载的文件
  mainWindow.loadFile('./src/index.html')
  // 开启渲染进程中的调试模式
  mainWindow.webContents.openDevTools()
  // 监听窗口关闭 销毁引用
  mainWindow.on('closed', () => {
    mainWindow = null
  1. 设置开启nodejs环境
    webPreferences.nodeIntegration: true

  2. enableRemoteModule保证renderer.js可以可以正常require(‘electron’).remote
    webPreferences.enableRemoteModule: true

  3. 设置窗口是没有边框的
    frame: false, // 是否有边框

文章目录例子html页面添加事件切换页面 和 打开窗口的方法例子html页面添加事件&lt;ul&gt; &lt;li&gt;&lt;button onclick="openNewWindow()"&gt;new BrowserWindow&lt;/button&gt;&lt;/li&gt; &lt;li&gt;&lt;button onclick="windowOpen()"&gt;window.open&lt;/button&gt;&lt;/li&gt; &lt;li&gt;&lt;butt tabs\文件夹,其中包含在选项卡中打开的示例页面 windows\文件夹,其中包含作为新窗口打开的示例页面 在应用程序首次启动时显示的windows\main\窗口,并显示一个包含所有选项卡链接的菜单 windows\tabs\包含从主菜单打开的所有选项windows\tabs\窗口 main.js应用程序的主要过程。 负责打开窗户并处理窗户之间的通讯 应用程序首次启动时,将打开一个新窗口( window\main\index.html )。 主窗口有一个包含三个链接的菜单。 这些链接可以引用此应用程序内的其他页面(请参阅链接1和链接2)或外部链接(请参阅链接3)。 当从菜单中选择一个链接时,该窗口会请求主进程打开一个带有标题和URL参数的 优雅地管理Electron的多个窗口并提供强大的功能。 此项目遵循git-contributor,该在Fri Dec 11 2020 11:31:32 GMT+0800自动更新。 $ npm i electron-windows --save const WindowManager = require ( 'electron-windows' ) ; const windowManager = new WindowManager ( ) ; const winRef = windowManager . create ( { name : 'window1' , loadingView : { url : '' , browserWindow : { width : 800 ,
原因也很简单:我们的应用要兼容多个平台,原生开发效率低,我们没有资源。说了跟白说一样,大部分选择Electron框架的动机都是差不多的,无非就是穷,尤其是在夹缝中生存的企业。为了优化客户端开发资源,'混合化'成为了我们今年客户端重构的主题。先来看一下我们现在的客户端基本架构:混合化对我们来说有两层意思:1.我们的应用架构'混合'了多种技术。通用底层C/C++,平台原生(iOS,Android,PC,MacOS),Web技术2.跨平台基于我们原有的客户端基础和情况,混合化重构自然而然分化为了两个方向:1.业务下沉。将通用的、核心的业务下沉。例如消息处理、语音/视频、会议、数据存储等核心模块,核心
<div class="header"> <span class="el-icon-minus" @click="minimizeWin"></span> <span class="el-icon-full-screen" @click="maximizeWin"></span> <span class="el-icon-close" @click="closeW 首先需要在渲染进程页面中引入一些模块,包括Menu、MenuItem、remote。 const {remote, clipboard} = require('electron') const {Menu, MenuItem} = remote; 然后添加监听事件“contextmenu”,实现对右击鼠标的事件监听。 setMenu() { var electron = require('electron') var app = electron.app var BrowserWindow = electron.BrowserWindow var mainWindow = null app.on('ready', () => { mainWindow = new BrowserWindow({ width: 400, height: 300, webPre 具有Element UI,axios,iconfont,权限控制和lint的最小vue管理员模板 现场演示: : 当前版本是基于vue-cli v4.0+ 。 如果要使用旧版本,可以将分支切换到 ,它不依赖vue-cli # clone the project git clone https://github.com/PanJiaChen/vue-admin-template.git # enter the project directory cd vue-admin-template # install dependency npm install # develop npm run dev 这将自动打开 # build for test environment npm run build:stage # build for pr
获取鼠标窗口句柄名称和值, public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); [StructLayout(LayoutKind.Sequential)] public struct RECT public int Left; //最左坐标 public int Top; //最上坐标 public int Right; //最右坐标 public int Bottom; //最下坐标 public Form1()
在系统任务栏中为您的应用程序快速创建可自定义的菜单/弹出窗口。 电子托盘窗口,基本上将窗口放在托盘图标附近。 在这些情况发生时,您可以自定义窗口/任务栏或跟踪事件。 npm install electron-tray-window yarn add electron-tray-window const trayWindow = require ( "electron-tray-window" ) ; 您可以使用不同的方式。 “ setOptions()”函数接受对象值。 如果您已经在TrayWindow外部创建了任务栏或窗口,则可以将其作为参数传递给.setOpt
https://blog.csdn.net/lucky_fang/article/details/125264788 最近做了一个electron+vue的项目,需要实现类似QQ边缘自动隐藏的功能。 一开始想到的是通过页面的mouseout、mouseenter、mouseleave等方法实现,通过查找了很多资料,发现这几个方法只能实现一些比较简单的交互,局限性很大,难以实现鼠标hover显示,out就隐藏的效果。 后来发现通过监听鼠标在窗口的位置可以非常方便实现鼠标hover和out的判断,从而实现窗口自动隐现功能。 remote模块提供了一种在渲染进程(网页)和主进程之间进行进程间通讯(IPC) 的简便途径。 Electron中,与GUI相关的模块(如dialog, menu等)只存在于主进程,而不在渲染进程中。 为了能从渲染进程中使用它们,需要用ipc模块来给主进程发送进程间消息。使用remote模 块,可以调用主进程对象的方法,而无需显式地发送进程间消息,这类似
chrome浏览器不支持webgl(webgl context must not be null, please enable webgl in your browser settings!) 小楼窗外的细雨: 解决是解决了,不报错了。但是,选了这个 Choose ANGLE graphics backend 为"OpenGL",模型渲染很卡。 express 处理代理请求(express-http-proxy) m0_51273292: It's working thanks so much![code=javascript] // 转发主产品的模块 // 从系统环境变量中获取TOKEN const token = process.env.TOKEN as string; // /main/xxx转发到https://api.talesofai.cn/xxx,然后带有一个请求头x-token,要求转发的请求头也带有x-token,要支持GET/POST/PUT/DELETE import * as proxy from "express-http-proxy"; app.use( "/main", loginCheck, proxy("https:/bugaosuni.com/", { proxyReqPathResolver: (req) => { const newPath = req.originalUrl.replace("/main", ""); return newPath; proxyReqOptDecorator: (options, req) => { options.headers = options.headers || {}; options.headers["token"] = token; return options; userResHeaderDecorator: (headers, userReq, userRes, proxyReq, proxyRes) => { headers["token"] = token; return headers; [/code] vue2.x之vuex module模块学习笔记(二) programmer_ada: 你要暗自努力然后惊艳所有人。 promise的finally方法 江户川柯南659: 5w浏览量,没人看出来博主说的结果是错的吗。。