Importing contents of one HTML file into another, from a CD?
January 17, 2005 8:08 AM   Subscribe

Plain old HTML: is there any way to get the contents of HTML file A into HTML file B without using frames, iframes, PHP or other server side stuff (it's for on a cd), and just copy-pasting the contents of one into the other? So something like an import function (perhaps done with javascript)? I need a page with a TOC + content and want to make it pretty, so frames are a no.

To make sure I don't seem lazy: I'm not asking for js code or anything, just if there's another fairly well-known way I haven't thought about or have forgotten.
posted by Skyanth to Computers & Internet (12 answers total)
 
Since it's for static pages on a CD, then you're somewhat limited; I'm sure that there are Javascript tricks you can use, but I have to admit I'm totally unclear why frames are a bad thing for this. They can be styled unobtrusively, they are pretty flexible, and they're exactly intended for what you describe.
posted by delfuego at 9:14 AM on January 17, 2005


i think this answers your question.
posted by escher at 9:17 AM on January 17, 2005


I suppose you could have a javascript function that reads in your data and writes the html to the page. You might have to make file B something like var x = 'allYourCode'; and then name it fileB.js or something. You could then put a script reference to the file in your headers and a document.write(); in your body. I'd think that would do it.
posted by spaghetti at 9:18 AM on January 17, 2005


Also...I think I remember doing this once with a div tag that specified an external document as a source...it's been a while since I've done anything outside of server side scripting for includes, but I remember that working quite well.

Good link escher!
posted by spaghetti at 9:23 AM on January 17, 2005


Response by poster: Small frame rant coming up, frame lovers avert your eyes:

They are useful, as you say, for simple stuff. But!

1. They are ugly. You get an ugly grey separator, or, if you use no border, a white separator.

2. They are unreliable. If you have two horizontal frames (say navbuttons on top and contents in the bottom one) and open another frameset in the lower one, all of the nav buttons with target "bottom frame" open in a new window instead of just removing the second frameset and displaying the page they should. So you have to use a workaround.

I don't like this, because I get the distinct feeling that none of the current browsers bother to implement frames in a sensible way.

So I'm /probably/ going to have to use them anyway, but not if it can be helped.
posted by Skyanth at 9:28 AM on January 17, 2005


Frames are pretty much the only way to do this clientside. I know you want to make it pretty, but if that's the only reason, there's no reason to dismiss frames out of hand since you wouldn't be using them in the traditional way.

The way I'd approach something like this is to create a hidden frame, that is a frameset with two rows (100%,*). The top row contains your main TOC + content, and looks and acts for all the world like a regular HTML page (HTML file B). The bottom, hidden frame contains HTML file A.

HTML file B uses javascript to weasel its way up the frameset and back down into HTML file A, grabs whatever content it needs, ranging from the whole file to any individual tag, then lugs it back to the main frame, again using javascript and then uses innerHTML() to dump it back out to the screen, seemlessly integrating the new content with its own content.

On preview, spaghetti, you might be thinking of Netscape 4's layer tag, which could have an external src defined. Would have worked well for this problem...
posted by Jeff Howard at 9:30 AM on January 17, 2005


Response by poster: Ah, just saw that link. Thanks, Escher!
posted by Skyanth at 9:33 AM on January 17, 2005


so you want something like this:

[TOC][Content linked from TOC]

where clicking a link in the TOC will load up the appropriate section of the page into the content region?

if it's on a disk, one of the things you have going for you is that there's no upload time. so, why not just include the full TOC in every file? aside from the pain-in-the-ass of adding it in, mind you.

an alternative if this whole thing is just text or fairly simple is to throw in a CSS hide, leave all the contents as hidden divs, open them up by hiding one and showing another. then again if you're targeting browsers that can do that, iframes are smarter and a more sane solution.

finally, um... PDF? that's one of the things that acrobat excels at. you can even throw a copy of the acrobat 6/7 install for old/new computers on the disk. it can import HTML. if you don't have a copy of the program, makes it harder; you'd have to find someone who would let you use their computer to put it together, but that might be easier for deploying static pages.
posted by caution live frogs at 9:45 AM on January 17, 2005


If you're burning this stuff onto a CD, why not just keep your table of contents in a separate file while doing development and then use a macro processor like m4 at the last minute before burning to stick the TOC fragment into each of your individual pages?
posted by letourneau at 10:07 AM on January 17, 2005


What letourneau says is good, another way is to write the site using PHP or whatever server side scripting you're happy with.

Then use (or write) something that downloads the whole site (what-ever the modern day version of web-whacker is), burn *that* onto the CD-Rom.

That's the fastest way I can think of (and I actually do do this, but I use ColdFusion to create and grab the pages/site) and avoids the client needing to have javascript working, unless you have other javascripty type things on the page.
posted by ModestyBCatt at 12:22 PM on January 17, 2005


I don't like this, because I get the distinct feeling that none of the current browsers bother to implement frames in a sensible way.

Use an inline frame, more commonly known as an <iframe> ... you can set the border="0" and its demensions to a reasonable size and there won't be any of the artifacts you described above.
posted by furtive at 4:35 PM on January 17, 2005


Response by poster: Okay guys/girls, thanks for all your excellent ideas. You've given me a lot of inspiration.
posted by Skyanth at 11:34 PM on January 17, 2005


« Older Can I add the currently playing song to my iPod...   |   Anime That Is Either Scifi or About Traditional... Newer »
This thread is closed to new comments.