Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Best way to include an html file with JavaScript

    Hi all,

    I am trying to find a way to include a .html file in my client side only site (say for example: header.html).
    Normally I would do this using PHP's include() function.

    Is the best way to do this in JavaScript to create a .js file and have the html in a string and use <script> to bring it in?

    Thanks!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Since not everyone has JavaScript there is no way to add content to the page using JavaScript that will work for everyone.

    You can embed an entire separate web page into HTML using an object tag (which replaced the old iframe tag back in 1997) in the HTML itself. Any HTML you add from JavaScript will only be seen by some visitors.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    May 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    Since not everyone has JavaScript there is no way to add content to the page using JavaScript that will work for everyone.

    You can embed an entire separate web page into HTML using an object tag (which replaced the old iframe tag back in 1997) in the HTML itself. Any HTML you add from JavaScript will only be seen by some visitors.
    Thanks Felgall,

    Are you able to elaborate a little more?

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,665
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    Quote Originally Posted by MeltingDog View Post
    Are you able to elaborate a little more?
    http://joliclic.free.fr/html/object-tag/en/index.php


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •