Include content from one page to another with HTML Code

stevenpetersen -1 Tallied Votes 345 Views Share

Include content from one page to another with HTML Code.
On the page that you want to put content on just insert <!--#include virtual="YourURL"--> <html>
<body>

<!--#include virtual="YOUR URL" -->

</body>
</html>

<!--#include virtual="YOUR URL" -->

Dani AI

Generated

A short, practical summary based on the thread: native HTML has no built‑in “include” tag. Pulling one page into another is normally done either on the server (SSI, PHP, ASP) or on the client (AJAX/Fetch); the comment‑style directive shown earlier is an SSI-style directive and only works when the web server is actually parsing pages for server‑side includes. As demonstrated the form, and as advised, confirm which server technologies the host supports before proceeding. (httpd.apache.org)

If using Apache SSI, the server must run mod_include and the directory must allow includes. A common .htaccess setup (when allowed) is:

Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

Place SSI pages under that directory and test: if the SSI directive appears raw in “view source” the server did not parse it. Host control panels or support can confirm whether AllowOverride and mod_include are available. (httpd.apache.org)

If using a scripting language (PHP/ASP), pages must be parsed by that interpreter (use .php for PHP). A quick PHP sanity check is a small test file that runs phpinfo() to confirm parsing. Do not include remote URLs via include/require unless the server intentionally allows it (php.ini options like allow_url_fopen / allow_url_include) — allowing remote includes is a common vector for Remote File Inclusion attacks; prefer local files and a whitelist. See PHP docs and OWASP guidance on file‑inclusion risks. (php.net)

A simple client‑side fragment load is also an option (works when same‑origin or when the remote server sends CORS headers):

fetch('/fragments/header.html')
  .then(r => r.text())
  .then(html => document.getElementById('header').innerHTML = html)
  .catch(e => console.error('include error', e));

Client fetches are subject to CORS restrictions. For troubleshooting: check view‑source, test a PHP file, ask host support, or use a build‑time/template approach (static includes) for better performance and security. (developer.mozilla.org)

xxxservicexxx 0 Newbie Poster

How does this work? I copy the all codes above to my existing page, it does not display anything.

drsim 0 Newbie Poster

first check if you are using the right DTD,
if you are including file from different domain than it wont work.

xxxservicexxx 0 Newbie Poster

Thanks drsim, I think I need to study more in Html, and how to use properly the Document type.. as of now, im a very new learner in html, noob one. Hope soon I'll have more knowledge in Webdesigning, I love too...just hate that I'm just a starter^^.

drsim 0 Newbie Poster

you are welcome, sure you will be master one day.good luck

almostbob 866 Retired: passive income ROCKS

the code supplied is WRONG
includes do not work in html
includes require shtml
the filename has to be altered to shtml and the server has to be configured to parse .shtml for server includes
base level hosting likely will not include .shtml .php or .asp
php & asp EAT .shtml for ability, popularity, available resources

useless codescrap

if wishing to ustilise server scripting of any sort, determine what the host package supports and use the highest

if a *n?x host likely supports .shtml and .php,, use php
if a windows host likely supports .shtml and .asp,, use asp (and get treatment whatever condition made you choose windows hosting :D )

xxxservicexxx 0 Newbie Poster

Thanks almostbob, I may not know much in this code but seeing your posts, I can see you know what your saying, from a hunch, I felt you have correct points and more experienced. When I know how this things work, I might come back here and post the correct codes and the required features in the server to work it completely.,coz this will be very useful in web designing/developing.
Or maybe some can post the correct codes or steps to make it work (pls show the complete codes)

almostbob 866 Retired: passive income ROCKS

once you have determined what server scripting language your host package supports, google a basic tutorial
w3schools.com has many, not perfect but,,,,
the correct code is already published, thats what the html/css php asp forums on this site do.
the include scrap works,, for shtml not html <?php include('filename'); ?> for php

experiment
attempt
ask
and whichever language you find to use, there will be someone to answer

xxxservicexxx commented: nice +1
xxxservicexxx 0 Newbie Poster

Thanks a lot almostbob. Yeah I gona try and experiment this things.

Mike_Slough 0 Newbie Poster

Almost Thanks a lot to share your very useful post.

Mike_Slough 0 Newbie Poster

Thanks to share nice code for our site.

Member Avatar for Member #120589
Member #120589

Oh man! Who the hell resurrected this old piece of rubbish? The code is bogus for HTML. Let sleeping farty old clapped-out dogs lie. Get a grip!

"The OP has left the building".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.