【发布时间】:2017-03-04 14:39:32
【问题描述】:
我是 JS 开发的新手,基本上来自 PHP 背景。我想知道是否有一种方法可以像我们在 codeigniter(加载视图)中那样包含 html 页面。我试图为我的电子应用程序创建一个模板结构,其中页眉和页脚文件被加载到每个请求的 html 页面上。
我无法尝试 jQuery 加载方法
$('#footer').load('header.html');
因为我需要在我创建的每个文件 html 文件的页脚中加载 jquery。 我尝试了JS加载html文件的方式
document.getElementById("head").innerHTML='<object type="text/html" data="header.html" ></object>';
但这基本上会创建一个类似于 iframe 的对象,因此您的资源永远不会习惯于使用 link 和 script 标签加载的方式。
我有一个 main.js 文件,主页将从那里加载:
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1280, height: 742, resizable:false})
// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'app/views/index.html'),
protocol: 'file:',
slashes: true
}));
}
如何在这种方法中直接附加页眉和页脚?如果有帮助,我也会使用 express。
【问题讨论】:
-
你用的是什么模板引擎?你说你正在使用 Express。通常您使用模板引擎,除非您使用 SPA(角度等)。
-
Angular 会有我所说的模板方案吗?
-
是的,您可以使用ngInclude 引入页眉和页脚。如果你愿意,我可以提供使用 ejs 和 Angular 的示例
-
是的,请...谢谢
标签: javascript node.js express electron