使用HTML5 API创建子窗口,控制窗口,窗口之间的交互,从子窗口返回数据,页面来源,使用eval方法向子窗口传递数据

index.js

/**
 * 使用HTML5 API创建子窗口
 * window.open方法
 * window.open(url[,title][,attributes])
 * 1、url:要打开页面的链接(可以是本地的链接,也可以是Web链接)
 * 2、title:设置要打开页面的标题,如果在页面中已经设置了标题,那么 这个参数将被忽略
 * 3、attributes:可以设置与窗口相关的一些属性,例如,窗口的宽度和高度 
 * window.open方法的返回值 
 * 
 * BrowserWindowProxy 可以认为是BrowserWindow的代理类
 * 
 * 控制窗口
 * 1、获取窗口焦点 focus
 * 2、让窗口失去焦点状态 blur
 * 3、关闭窗口:close
 * 4、显示打印对话框:Print
 * 
 * 窗口之间的交互:最简单的数据传递方式
 * B.postMessage(data,'*')
 * 
 * 从子窗口返回数据
 * ipcRenderer.send(...)
 * ipcMain.on
 * 
 * 页面来源:“谁”使用url打开的新的子窗口。在本例中,"谁"是指index.html所在的域名
 * e.origin
 * 
 * 使用eval方法向子窗口传递数据
 * eval方法用来执行JavaScript代码
 */
const {app,BrowserWindow} = require('electron');
function createWindow(){
    win = new BrowserWindow({
        //show:false,
        webPreferences:{
            nodeIntegration: true, // 是否集成 Nodejs
            enableRemoteModule: true,
            contextIsolation: false,
        }
    });
    win.loadFile('index.html');
    win.on("ready-to-show",()=>{
        win.show();
    });
    if(process.platform!="darwin"){
        win.setIcon("images\\logn.jpg");
    }
    win.on('closed',()=>{
        console.log('closed')
        win=null;
    });
}
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
    console.log('window-all-closed');
    if(process.platform!='darwin'){

    }
});
app.on('activate',()=>{
    console.log('activate');
    if(win==null){
        createWindow();
    }
});
View Code

相关文章:

  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-07-22
  • 2021-11-21
  • 2021-11-19
相关资源
相似解决方案