Equivalent of include() in HTML

后端 未结 11 475
有刺的猬
有刺的猬 2020-11-29 06:40

I was wondering wether there is a way to include some html content inside another html using only html?

A replacement to PHP\'s



        
相关标签:
11条回答
  • 2020-11-29 07:00

    There's no such thing. You'd have to use a server-side scripting language or JavaScript to do something like this.

    0 讨论(0)
  • 2020-11-29 07:01

    Almost 10 years later, some people may still have doubts about this. So I'm going to explain a simple solution that we have today in 2020.

    I always use the jquery .load() function and never had a problem with that.

    Exemple: ( "#content" ).load( "includes/menu.html" );
    
    0 讨论(0)
  • 2020-11-29 07:04

    If you're using Apache, you can try Server Side Includes.

    0 讨论(0)
  • 2020-11-29 07:07

    This might be a few years late but this is how i did it !

    in the first line after put this line !

    <SCRIPT LANGUAGE="JavaScript" src="http://yourdomain.com/header.js">
    

    then create a file called "header.js" and enter the content of the file you want to include ! like so....

    <!-- Begin
    document.write('<center>');
    document.write('<a href="http://alinktosomewhere.co.za">a link 1</a>');
    document.write('<a href="http://alinktosomewhere.co.za">a link 1</a>');
    document.write('<a href="http://alinktosomewhere.co.za">a link 1</a>');
    document.write('<a href="http://alinktosomewhere.co.za">a link 1</a>');
    document.write('<hr>');
    document.write('</center>');
    // End -->
    

    Hope this help !

    0 讨论(0)
  • 2020-11-29 07:13

    It cannot be done purely by HTML. (There are iframes, however, but I don't think that qualifies in this case.)

    It can be done using JavaScript. You get the other file via Ajax, and place its contents inside an HTML element on the current page.

    0 讨论(0)
  • 2020-11-29 07:14

    HTML does not have a feature to include additional content natively. However most web servers do have server-side include statements:
    SSI in Apache
    SSI in IIS

    0 讨论(0)
提交回复
热议问题