html5 imports,html - HTML5 Imports not working - Stack Overflow
The correct to do this is through server side pages includes or through JavaScript.
PHP example:
Welcome to my home page!
Some text.
Some more text.
Javascript Example:
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if (xmlhttp.status == 200) {
document.getElementById(“myDiv”).innerHTML = xmlhttp.responseText;
}
else if (xmlhttp.status == 400) {
alert(‘There was an error 400’);
}
else {
alert(‘something else other than 200 was returned’);
}
}
};
xmlhttp.open(“GET”, “header.html”, true);
xmlhttp.send();
}
Javascript with JQuery Library:
$.ajax({
url: “header.html”,
success: function(data){
$(“myDiv”).html(data.responseText);
}
});
If you don’t want to get your hands dirty in js you can do the following using a script provided by w3schools:
w3IncludeHTML();
还没有评论,来说两句吧...