Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2005
    Posts
    72

    javascript includes??

    Ok.. here is the deal. I am making a very large website with a drop down javascript menu. I am using HTML includes for various parts of the website (including the menu).

    The way it is now, If I need to make any changes to the drop down menu I will have to go to ever page on the website and change the javascript coding.. Is there a way to include this coding (similar to what I am doing with the HTML files)?

    Basically, I want to know if there is a way to set up a template where I can make the changes to the coding and not have to make the changes to each individual page..

    can anyone help?

    thanks

  2. #2
    Join Date
    May 2004
    Location
    Pflugerville, TX
    Posts
    11,222
    The answer to your question about an include system is yes, and further, a JavaScript include system is the worst possible way you can create one. Unless your server does not support PHP, ASP, ColdFusion or SSI, I would strictly keep away from serving up critical information, such as site structure, using JavaScript. Stick with server technology. Don't rely on the visitor UA to interpret your site!

    With that said, is there a specific reason you're targeting JavaScript, something in your environment that makes it the only option?
    Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design

  3. #3
    Join Date
    Feb 2006
    Location
    Lancashire, UK
    Posts
    473
    use php. create a file called header.php. put all your html in this file. then use php <? include "header.php"; ?> to include the files in your pages. when u want to change the pages, you just change header.php, rather than all the pages

  4. #4
    Join Date
    Oct 2005
    Posts
    72
    okay.. I know how to do PHP includes, but I'm not sure what you mean by putting all of the HTML in just one file..

    Is it possible to just have one inlcude file for the navigation (say: nav.php) which has the HTML/javascript for the navigation and just use that as an include?

  5. #5
    Join Date
    Oct 2005
    Posts
    72
    hmmm, I have tried using the php includes but I can't seem to get it to work so that I only have one file with the javascript code in it.. are there any links out there so I can see how the coding is done???

  6. #6
    Join Date
    Oct 2005
    Posts
    72
    okay.. I got the coding to work.. I always thought that javascript coding needed to go in the <head> part of a website.. The way I have it set up right now, the javascript is loaded in the body part of the website - is there anything wrong with that?

  7. #7
    Join Date
    May 2004
    Location
    Pflugerville, TX
    Posts
    11,222
    If you're using PHP includes, stick all of your JS functions into an external file. Then, use the common script calling mechanism to call those scripts - <script type="text/javascript" src="/path/to/scripts.js"></script>. Finally, place this inside the file that's being included via PHP. That's all there is to it

    Remember, you can include files inside included files, inside included files, ad nauseum.
    Studio1337___̴ı̴̴̡̡̡ ̡͌l̡̡̡ ̡͌l̡*̡̡ ̴̡ı̴̴̡ ̡̡͡|̲̲̲͡͡͡ ̲▫̲͡ ̲̲̲͡͡π̲̲͡͡ ̲̲͡▫̲̲͡͡ ̲|̡̡̡ ̡ ̴̡ı̴̡̡ ̡͌l̡̡̡̡.__Web Design

Posting Permissions

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