I am trying to build an app with electron,
(我正在尝试用电子构建一个应用程序,)
for that, i disabled the window frame to make my own frame navigation (fullscreen, minimize, close etc).. Since i want to have the menu which replaces the default OS frame navigation on every window, i want to make one html file which contains the whole html for the navigation and import that file in every html file.
(为此,我禁用了窗口框架以进行自己的框架导航(全屏,最小化,关闭等)。由于我想拥有一个菜单来替换每个窗口上的默认OS框架导航,因此我想制作一个HTML文件包含用于导航的整个html,并将该文件导入每个html文件。)
In jquery it would look like this: $("#elementWhereTheHTMLgoesIn").load("./nav/nav.html")
So, this actually works, but if i want to add an eventlistener to some elements in the loaded html part, for example: <ul><li id="appClose">X</li></ul>
chrome tells me can not read property of null .
(在jquery中,它看起来像这样: $("#elementWhereTheHTMLgoesIn").load("./nav/nav.html")
因此,这确实有效,但是如果我想向加载的html部分中的某些元素添加$("#elementWhereTheHTMLgoesIn").load("./nav/nav.html")
,例如: <ul><li id="appClose">X</li></ul>
chrome告诉我无法读取null属性 。)
it works with setTimeout(() => {$("#appClose").addEventListener("click", function bla bla)}, 1)
(它与setTimeout(() => {$("#appClose").addEventListener("click", function bla bla)}, 1)
)
any const/var/let with the value of $("#appClose")
causes the can not read property of null , the setTimeout is a workaround here, even 1ms is enough...
(任何具有$("#appClose")
值的const / var / let都会导致无法读取属性为null ,在这里setTimeout是一种解决方法,即使1ms也足够...)
So, is there any other good way to import html in html using js/nodejs/electron and not using jQuery's load()?
(那么,是否还有其他好方法可以使用js / nodejs / electron而不使用jQuery的load()在html中导入html?)
i know <link rel="import" href="./nav/nav.html">
is dead in 2020 sadly ..
(我知道<link rel="import" href="./nav/nav.html">
在2020年不幸去世了..)
ask by skyslide22 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…