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
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile include .html file in document.write

    Hi! how do I include .html files inside a document.write()?

    Like document.write('include top.html' "hello!" 'include bottom.html') or something.

    I searched for it, and found this:

    <!--#include file="top.html" -->

    But it doesn't work for me. What is wrong?

    I would be very happy if someone could help me

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by vilhelm View Post
    But it doesn't work for me. What is wrong?
    It doesn't work for anyone as JavaScript can't access files that way.

    See http://javascriptexample.net/ajax.php for a series of examples of how JavaScript can read files from the server.

    If you want to use that include statement then you have to have Server Side Includes turned on on your server and serve the pages using an extension that parses them through that module - usually using .shtml instead of .html

    If you use the include statement then it goes directly in the HTML and not in any JavaScript.
    Last edited by felgall; 05-18-2012 at 10:25 PM.
    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
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't do this but you can include an javascript file in your html file and in your another javascript file which will output your HTML file.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by whypro View Post
    You can't do this but you can include an javascript file in your html file and in your another javascript file which will output your HTML file.
    That makes no sense.
    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.


  •  

    Posting Permissions

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