patternjavascriptCritical
Include another HTML file in a HTML file
Viewed 0 times
includefileanotherhtml
Problem
I have 2 HTML files, suppose
In JSF I can do it like that:
It means that inside
How can we do it in
a.html and b.html. In a.html I want to include b.html.In JSF I can do it like that:
It means that inside
a.xhtml file, I can include b.xhtml.How can we do it in
*.html file?Solution
In my opinion the best solution uses jQuery:
This method is a simple and clean solution to my problem.
The jQuery
a.html:
$(function(){
$("#includedContent").load("b.html");
});
b.html:This is my include fileThis method is a simple and clean solution to my problem.
The jQuery
.load() documentation is here.Code Snippets
<html>
<head>
<script src="jquery.js"></script>
<script>
$(function(){
$("#includedContent").load("b.html");
});
</script>
</head>
<body>
<div id="includedContent"></div>
</body>
</html><p>This is my include file</p>Context
Stack Overflow Q#8988855, score: 844
Revisions (0)
No revisions yet.