Monday, January 4, 2010

Include Files into your HTML

Join GeekyClown's Fan Page on Facebook | Follow me on Twitter
Including a Web page inside another Web page makes creating sites simple.  For example, if you have a Web page with content and want to include your site's navigation you can use an include instead of copying and pasting the code into the page.  The reason to do this is simple, if you make changes to the included file, you only need to do it once instead of changing every single page on your site.

PHP, ASP, and ColdFusion all have tags that act as include tags.  However, HTML does not have an include tag built into the DTD.  There is a simple way around this, code everything through JavaScript and include the JavaScript file.

Note: The only downside is that if the user has JavaScript turned off, this will not work.

In the .js file (the included file):

You can put anything in this file, if it is basic HTML, simply use document.write("<MY HTML TAGS>")

Save it as .js.

In your file, just call the JavaScript file into the page <script language="JavaScript" src="my file to include.js"></script>

No comments:

Post a Comment