Reputation:
I've got an index page and I want to load on a DIV another page from a very different directory, but I want that the page that will be loaded into the DIV to keep the CSS and JS includes, is it possible?
It seems that it only loads into the DIV, the body of the other page and forget the JS and CSS includes.
I'm using this code to load the HTML into the div:
<script type="text/javascript">
function processAjax(url) {
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = targetDiv;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = targetDiv;
req.open("GET", url, true);
req.send();
}
}
}
function targetDiv() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
document.getElementById("mContent").innerHTML = req.responseText;
} else {
alert("Problem: " + req.statusText);
}
}
}
</script>
<a href="javascript:processAjax('./DataTables/extras/Editor/treinamentos/index.html');">My Page</a>
Upvotes: 1
Views: 2792
Reputation: 731
Why don't you use an IFRAME tag that contains the url of the page you desire to display with the js and css you want to use.
<iframe src="mypage.html"></iframe>
Upvotes: 3