SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Addict michaelwheaton's Avatar
    Join Date
    Jan 2001
    Location
    Alberta, Canada
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Include HTML with JavaScript???

    I'm working on a site which needs to include HTML from an external file, but the server doesn't support SSI. I think I read about this a while ago, but I don't remember how it was done.

    Could someone help me out with the code to do this?

    Thank you,
    Mike

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2000
    Location
    Australia
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Include this line where you want the "insert" to be...

    Code:
    <script src="jslink.js" language="javascript">
    </script>
    And then you need an include file that looks something like this...

    Code:
    <!-- Hide Script From Incompatible Browsers
    
    include_content = "<img src='/mtffafl/Images/Navigation/mypages-top.jpg' width='127' height='31'><br>" +
    	          "<a href='/mtffafl/Division1/Teams/index.html'><img src='/mtffafl/Images/Navigation/myteam-fade.jpg' width='127' height='29' border='0' name='myteam'></a><br>"
    
    document.write(include_content);
    
    // Hide Script -->
    You could alternatively do it with a series of document.write commands instead...

    Code:
    document.write("The first include line")
    document.write("The second include line")
    etc.
    I had to use this technique once on a free server I was using that didn't have SSI or ASP.

    Hope this helps,
    Matt

  3. #3
    SitePoint Addict michaelwheaton's Avatar
    Join Date
    Jan 2001
    Location
    Alberta, Canada
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the advice, Matt- but is there any way to include a regular HTML file instead of .js? I am trying to include a file that is generated by a PHP script. This script generates a regular HTML file, and I'm not sure if it could be adapted to create .js without a lot of extra work.

    I thought I saw a method a while ago that used something like "type=HTML/text" inside the script tag. Does this sound right? If I can't use javascript to include a regular HTML file, does anyone know of other methods?

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2000
    Location
    Australia
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The file extension isn't important - so it could be .js or .html

    However, I assume you also mean it is generating HTML instead of javascript.

    Other than adapting the PHP to produce a javascript file I cannot help you, sorry...

    If PHP is available on the server is there a way to do it using PHP instead?

    Matt

  5. #5
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Although JSRS was intended for use with server-side scripting, it should work perfectly well with static HTML pages:
    http://www.ashleyit.com/rs/
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2000
    Location
    Australia
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Knew I should have left it to a higher authority

    Matt

  7. #7
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not at all - always post whatever you know!
    (or whatever you think you know...! )
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  8. #8
    SitePoint Addict michaelwheaton's Avatar
    Join Date
    Jan 2001
    Location
    Alberta, Canada
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the help, but I still haven't been able to get it to work yet. Here's the code I'm using:

    <script src="toplinks.html" language="javascript"></script>

    Could it be that the language needs to be changed from javascript to something else? I'm also getting a runtime error in IE that wasn't there before.

    Any ideas?

  9. #9
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    michaelwheaton, check out the link I posted!
    (that's NOT how you use JSRS)
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  10. #10
    SitePoint Addict michaelwheaton's Avatar
    Join Date
    Jan 2001
    Location
    Alberta, Canada
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about that, I only took a quick look at the site and didn't realize there was anything I needed to download. I'm still a little confused about what JSRS is exactly, and what I should do with these files I downloaded.

    Do I just upload all of the files in the jsrs_php ZIP file to the website? I can't find any file which shows how to actually include the seperate HTML file into the page.

    Sorry about all of this- I'm clueless when it comes to programming/scripting.

  11. #11
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, red herring, I'm afraid! Upon closer inspection, I have realised JSRS will not be able to do what you need - it DOES require server-side scripting capability.

    For the moment, the only thing that I can suggest is to use an IFrame.

    I could write an ASP script which would take a given URL and return the page body as a JS string which you could then use like this:

    Code:
    <DIV>
    <SCRIPT SRC="http://aspserver/geturl.asp?url=www.google.com"></SCRIPT>
    </DIV>
    But you would need an ASP host to run it on - I cannot offer the use of my own web space, since I have no idea what you are using it for, how much bandwidth it will generate, etc.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  12. #12
    SitePoint Addict michaelwheaton's Avatar
    Join Date
    Jan 2001
    Location
    Alberta, Canada
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An iframe has been considered- but we would prefer not to use one because of the problems it will cause with older browsers and Netscape. Also, I don't believe that they are indexed by search engines, and the area I am trying to include is a link exchange box- so much of the benefit of the exchange would be lost.

    The server doesn't support ASP, but it does allow PHP. Would that same tag work with a script source of a PHP file? I was never able to get it to work before- but I also didn't enclose it in DIV tags.

  13. #13
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm afraid you misunderstand me - the code I posted would work if I created an ASP page (in that example called "geturl.asp") which reads the specified URL, and returns it as a series of JS document.write("blah blah blah") statements, which the browser then executes, and voila!

    However, if you have PHP support, you could do exactly the same using JSRS, although you will clearly need help from a PHP coder to do so (I'm an ASP man).
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!

  14. #14
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by michaelwheaton
    An iframe has been considered- but we would prefer not to use one because of the problems it will cause with older browsers and Netscape. Also, I don't believe that they are indexed by search engines, and the area I am trying to include is a link exchange box- so much of the benefit of the exchange would be lost.
    Just wanted to comment on this for the general good of anyone reading this thread... the iframe URL would be crawled as it is just a link to a separate document in a new window. JS src file content would not be crawled as search engines generally don't bother with JS... let alone JS src files. You should never use JS src files for navigation or any content you want crawled, because it won't be. (personal experience talking here)

  15. #15
    The doctor is in... silver trophy MarcusJT's Avatar
    Join Date
    Jan 2002
    Location
    London
    Posts
    3,509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up Thanks for pointing that out, freelancerx!

    His dependence on search engine crawling had slipped past me unnoticed (mostly because it wasn't mentioned earlier, but I should have spotted it in his last post).

    You're quite right in what you say - I'm not aware of ANY search engine that does parse/execute JS and index the resulting content. This of course comes as no surprise, due to the huge amounts of additional processing power that would be required to perform such a task (not to mention the fact that a pretty negligible number of sites would actually benefit).
    Last edited by M@rco; Oct 28, 2002 at 16:43.
    MarcusJT
    - former ASP web developer / former SPF "ASP Guru"
    - *very* old blog with some useful ASP code

    - Please think, Google, and search these forums before posting!


Bookmarks

Posting Permissions

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