简体   繁体   中英

Include another HTML file in a HTML file - with script execution

I have a part of html code which is repeating on every of my page and i want to reuse it.

There is already a very nice link: Include another HTML file in a HTML file

I have used jQuery to load the html file (separate html file which i call template).

If that html file is static everything is working fine. But if my template file includes the elements which are using class (CSS) which is using java script to load - then it's not being loaded. Even if in original html file i am referencing correct css/java scripts in head section. Any ideas ?

Thanks,

If you wanna include page1.html into an Div with id insert-into-me . page2.html.

Then using Jquery this will work!

<html> 
  <head> 
    <script src="jquery.js"></script> 
    <script> 
    $(function(){
      $("#insert-into-me").load("page1.html"); 
    });
    </script> 
  </head> 

  <body> 
     <div id="insert-into-me"></div>
  </body> 
</html>

Using JSP:

    <%@include file="page2.jsp" %> 
                or
    <jsp:include page="..." />

where you want to include in page1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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