[英]Load HTML into a DIV, but keeping the CSS,JS includes
我有一个索引页面,我想从一个非常不同的目录加载DIV另一个页面,但我希望将加载到DIV的页面保持CSS和JS包含,是否可能?
它似乎只加载到DIV,其他页面的主体并忘记了JS和CSS包含。
我正在使用此代码将HTML加载到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>
为什么不使用包含要与要使用的js和css一起显示的页面的URL的IFRAME标记。
<iframe src="mypage.html"></iframe>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.