javascript - 如何定义 Electron 文件?

标签 javascript html dom electron

我发现的其他stackoverflow问题没有帮助我,所以我问你。如何在 Electron 中的html/javascript中定义文档。错误:“未定义文档”。

html代码:

  <div id="container">
      <div id="left_panel"> left content! </div>
      <div id="right_panel">
          <div id="drag"></div> right content!
      </div>
  </div>

javascript:
const {app, BrowserWindow, Menu} = require('electron');
const url = require('url');
Menu.setApplicationMenu(false);
var isResizing = false;
var lastDownX = 0;

function boot() {
  win = new BrowserWindow({
    'minHeight': 300,
    'minWidth': 300
  })
  win.loadURL(url.format({
    pathname: 'index.html',
    slashes: true
  }))
}

app.on('ready', boot);

(function() {
    var container = document.getElementById("container"),
        left = document.getElementById("left_panel"),
        right = document.getElementById("right_panel"),
        handle = document.getElementById("drag");

    handle.onmousedown = function(e) {
        isResizing = true;
        lastDownX = e.clientX;
    };

    document.onmousemove = function(e) {
        // we don't want to do anything if we aren't resizing.
        if (!isResizing) {
            return;
        }

        var offsetRight = container.clientWidth - (e.clientX - container.offsetLeft);

        left.style.right = offsetRight + "px"; 
        right.style.width = offsetRight + "px"; 
    }

    document.onmouseup = function(e) {
        // stop resizing
        isResizing = false;
    }
})();

如果我得到帮助,那就太好了。
谢谢

最佳答案

executeJavascript方法也许可以在这里为您提供帮助。这使您可以访问文档对象。它返回一个Promise,因此您将不得不从中拉出Elements。

关于javascript - 如何定义 Electron 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61542281/

相关文章:

javascript - 在 jQuery 中弹出预先挂起的 div 项目(在消息接收时)

.net - 基于 HTML 的报告被分页撕成碎片

html - 是否可以通过在 HTML 和 CSS 中创建表格来实现

javascript - 使用纯 javascript 查找 #wrapper 中是否有 img

javascript - 将 jQuery 插件绑定(bind)到尚不存在的元素上

javascript - 如何添加向上箭头以选择元素以及向下箭头并仅使用这些箭头遍历选项?

javascript - 将 Y 轴移动到另一侧后的 Highcharts reflow()

javascript - 如何在 HTML 中更改 ul 标签 css 的属性

javascript - 我可以在用 JS 创建的 HTML5 视频元素上指定多个源元素吗?

javascript - classList.contains ('outputDiv' ) 在 IE 9 及更早版本中不受支持,