简体   繁体   English

将HTML加载到DIV中,但保留CSS,JS包括

[英]Load HTML into a DIV, but keeping the CSS,JS includes

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? 我有一个索引页面,我想从一个非常不同的目录加载DIV另一个页面,但我希望将加载到DIV的页面保持CSS和JS包含,是否可能?

It seems that it only loads into the DIV, the body of the other page and forget the JS and CSS includes. 它似乎只加载到DIV,其他页面的主体并忘记了JS和CSS包含。

I'm using this code to load the HTML into the div: 我正在使用此代码将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>



Usage: 用法:

 <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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM