www.webdeveloper.com
Results 1 to 14 of 14

Thread: load external HTML code

  1. #1
    Join Date
    Jan 2010
    Location
    new iberia, LA
    Posts
    4

    load external HTML code

    hello all. im new here. i have a big problem with the website i work on. i currently work on the website for New Iberia Senior High. i did not write the code but i maintain it and my job right now is to clean it up and condense it if possible. my problem is that on EVERY page of the site there are about 200 lines of code that load ONLY the menu bar. this much code makes it really hard to find what needs to be updated. is there a way i can move the code for the menu bar into a seperate text or html file and somehow load or import the code from that file into the other html file? help is much appreciated. if you want to see the source for the site go to http://nish.iberia.k12.la.us

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Best way would be carve out the common code into a separate file (like you're suggesting) and to use some sort of server side include - looks like you have PHP 5.2 available so that's an option, as is the straight SSI from Apache.
    Last edited by TheBearMay; 01-14-2010 at 11:28 AM.
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    you can move all the <script> tag's content into one external .js file, that will help a bit and requires no server-side adjustments.

    also, you can move the <style> tags into .css files.

    if you want to move HTML, you'll need to use ajax, SSI, or PHP to include an external file into the page.

  4. #4
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,278
    Don't use Ajax or any other JavaScript for this; it tends to not work. You would do better to use XHTML and external entities. Not that external entities are well supported but they're better supported than JavaScript these days.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by Charles View Post
    Don't use Ajax or any other JavaScript for this; it tends to not work. You would do better to use XHTML and external entities. Not that external entities are well supported but they're better supported than JavaScript these days.
    javscript is supported by all current web browsers, even those inside of the Wii and iPhone. in fact, of the 40 or so browsers listed on this wikipedia collection, only 6 old browsers can't run javascript:
    Amaya, Dillo, Mosaic, NetSurf, WorldWideWeb, w3m
    anyone you know use any of these?

    XHTML is deprecated, while javascript is integral to new standards like ARIA and HTML5.
    you sig says "Access by everyone regardless of disability is an essential aspect.”
    well, you need javascript to do that these days: ARIA cannot work without it.

    I do think that SSI, or PHP would be preferable solutions since they work for noscript users like me, but i think it's misleading to say that xml is better supported. Don't forget that (sadly) 2/3 surfers use IE, which doesn't even fully support XHTML...

  6. #6
    Join Date
    Jan 2010
    Posts
    25
    XHTML is a standard, one that is being improved upon as part of HTML 5, IE has supported XML/XSLT since IE 6, which covers most of IE's market share by now (IE5 tapering off into obscurity). XHTML, being a form of XML, is bound to be supported.

    Although Javascript is comparably supported, it sometimes isn't available due to the user turning it off or avoiding it via other means.

    These are the two most practical solutions.

    1. Use the include function from PHP and change the file types to .php instead of .html. Basically add the HTML header to it's own file and type "include(FILENAME);" where you want it to show on the page and that's it.

    2. SSI's. I actually have never used these, so i don't know how easy they are, but people who don't program can use them so it can't be terribly difficult.

    Don't use Javascript for this, it is the wrong tool for the job, and is subject to user issues.

  7. #7
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,278
    XHTML is depricated? Not at all. But on the other hand, to say that "XHTML, being a form of XML, is bound to be supported" is a little misleading.

    MSIE doesn't understand application/xhtml+xml, it treats it as text/html and you would be better off sending it real HTML. But it has excellent support for text/xml so you can save your XHTML with an XML extension, serve it as text/xml and give it an XSL style sheet that transforms it to HTML and then you can use external entities.

    From the Web Content Accessibility Guidelines 1.0, "Ensure that pages are usable when scripts, applets, or other programmatic objects are turned off or not supported. If this is not possible, provide equivalent information on an alternative accessible page."
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  8. #8
    Join Date
    Jan 2010
    Location
    new iberia, LA
    Posts
    4

    Exclamation

    im having problem doing ssi and php. ive looked at tutorials and asked around for help and i followed everything to the letter but it wouldnt work. anybody know what im doing wrong? i have a new folder holding 2 files, inavigation.ssi and index.html. the ssi file has the code for the menu bar and index.html has the rest of the site. in index.html i have <!--#include virtual="navigation.ssi" --> please help!

  9. #9
    Join Date
    Aug 2006
    Posts
    1,934
    Quote Originally Posted by pyromaniac1992 View Post
    im having problem doing ssi and php. ive looked at tutorials and asked around for help and i followed everything to the letter but it wouldnt work. anybody know what im doing wrong? i have a new folder holding 2 files, inavigation.ssi and index.html. the ssi file has the code for the menu bar and index.html has the rest of the site. in index.html i have <!--#include virtual="navigation.ssi" --> please help!
    For SSI, you'd need to rename your index.html file to index.shtml. And if you used PHP includes, you'd need it named index.php

    Dave

  10. #10
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,278
    Quote Originally Posted by tracknut View Post
    For SSI, you'd need to rename your index.html file to index.shtml. And if you used PHP includes, you'd need it named index.php

    Dave
    Not always true but true often enough.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  11. #11
    Join Date
    Jan 2010
    Location
    new iberia, LA
    Posts
    4
    Quote Originally Posted by tracknut View Post
    For SSI, you'd need to rename your index.html file to index.shtml. And if you used PHP includes, you'd need it named index.php

    Dave
    i tired that but when i went to rename the index file to index.shtml it gave me a warning saying the folder index_files (holds the menubar images and such) will no longer be associated with this file. how do i fix this?

  12. #12
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Quote Originally Posted by pyromaniac1992 View Post
    i tired that but when i went to rename the index file to index.shtml it gave me a warning saying the folder index_files (holds the menubar images and such) will no longer be associated with this file. how do i fix this?
    Have you saved your files to the desktop?
    Check all path names of included files are still correct.

  13. #13
    Join Date
    Jan 2010
    Location
    new iberia, LA
    Posts
    4
    Quote Originally Posted by Fang View Post
    Have you saved your files to the desktop?
    Check all path names of included files are still correct.
    the files are saved on a networked drive provided by the school. it holds every sing file and folder the website uses. no path names change in the code. i get that warning message AS i change index.html to index.shtml. im still clueless as to what to do

  14. #14
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by pyromaniac1992 View Post
    the files are saved on a networked drive provided by the school. it holds every sing file and folder the website uses. no path names change in the code. i get that warning message AS i change index.html to index.shtml. im still clueless as to what to do
    go ahead an change it, then update all the links in index.shtml that refer to the old paths. some editors, like dreamweaver, can do the link-reqwriting for you.
    usually, a find a replace or two can take care of the conversion.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles