简体   繁体   English

如何在新窗口中用电子打开哈希(#)链接?

[英]How open link with hash (#) in new window with electron?

I want open link in new window. 我想在新窗口中打开链接。 Link with hash (#). 链接哈希(#)。 After hash going page for my JS framework. 在我的JS框架的哈希页面之后。 I do: 我做:

const modalPath = path.join('file://', __dirname, 'index.html#','message',chat_id,'child-window');
let win = new BrowserWindow({width: 400, height: 200, show: false, frame: false});
win.loadURL(modalPath);
win.show();

It is worked for mac, but not work for Windows (open only index.html- mainpage) 它适用于mac,但不适用于Windows(仅打开index.html-主页)

Using path.join to build a URL is not a good idea since the path separators will differ between platforms, on Windows you'll end up with something like file://\\dirname\\index.html#\\message\\chat_id\\child-window , whereas on Mac/Linux you'll get file://dirname/index.html#/message/chat_id/child-window . 使用path.join构建URL不是一个好主意,因为路径分隔符在不同平台之间会有所不同,在Windows上你最终会得到类似file://\\dirname\\index.html#\\message\\chat_id\\child-window ,而在Mac / Linux上,你将获得file://dirname/index.html#/message/chat_id/child-window What you should do instead is something like: 你应该做的是:

url.format({
  protocol: 'file',
  pathname: `${__dirname}/index.html#/message/${chat_id}/child-window`
})`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM