Valhalla Legends Forums Archive | Web Development | Inserting one html file into another

AuthorMessageTime
Lenny
Is there any way to insert one html file into another using javascript or html?

To clarify, is it possible to append to the bottom of one html file text from another file?

Frames would seem like a very expensive way to do this, especially when there could be hundreds of them.
June 17, 2005, 5:42 PM
R.a.B.B.i.T
Use php!

[code]<?php

    // this is index.php
    echo "omg blah blah blah brbbbq<BR>";
    include('morerandomcrap.htm');

?>[/code]

[code]<!--
this is morerandomcrap.htm
//-->
<h1>OMGROFLWAFFLE!!!</h1>[/code]

As for JS, I don't know how, but I'm sure there's a way.  As for doing it in HTML, not possible.
June 17, 2005, 11:33 PM
KkBlazekK
Do NOT use include.

[code]
<?php
require_once "Blah.html";
?>
[/code]
Thats the best of the 4 requires/includes.
June 18, 2005, 12:32 AM
Arta
Why?
June 18, 2005, 1:56 AM
KkBlazekK
You could go off in a loop if a page is poorly constructed.

Example of a poorly constructed page:
[code]
<?php
    $bob = $_GET[page]
    include "../".$bob
?>
[/code]

index.php?page=index.php would loop on forever.

Use require so the page will stop loading as soon as it hits the error.
June 18, 2005, 2:16 AM
KoRRuPT
I would use,
[php]
<?
echo file_get_contents('file.html');
?>
[/php]

I would use this because PHP will parse the file if you use include() or require(). Considering that you know that there isn't any PHP in "file.html", its just best to use file_get_contents, because all its doing is reading the file and spitting out the data.
June 18, 2005, 2:17 AM
Quarantine
It also allows you to construct an optional templating engine replacing tags that you define :]
June 18, 2005, 2:19 AM
Arta
[quote author=Blaze link=topic=11871.msg116285#msg116285 date=1119061019]
You could go off in a loop if a page is poorly constructed.
[/quote]

In other words, it hides bad design? require_once wouldn't fail on a recursive or circular include.

You'll notice a bad include pretty quickly whther you're using require or include. What does it matter?

Prior to version 4.0.something, require is not affected by conditional statements. In other words, this require would always execute:

[code]
if(false)
{
  require 'x.php';
}
[/code]

Thus, I contend that require is bad; include is much more reliable and no less error prone, assuming you have warnings enabled on your development box.
June 18, 2005, 2:29 AM
Quarantine
sometimes you have code that can't be declared more than once (classes) and you may have a file that accidently includes it once (and to save you the trouble of worrying about it) include_once makes sure not to re-include if it already has been.
June 18, 2005, 2:32 AM
Arta
Accidentally being the key word. Languages shouldn't help programmers desguise bad design choices. require_once and include_once are both things that lull one into a false sense of security - rather like "on error resume next".

Require is fine for most things, but problem-prone on servers running old versions of php. Include is safer, and is thus a better choice.
June 18, 2005, 2:43 AM
Lenny
Well as far as using javascript goes...

Is it possible to do anything similar to a countdown, where a number is displayed after 1 second has passed?

[quote]
5
4
3
2
1
[/quote]

I'm having issues where window.setTimeout() and window.setInterval() only fire once with document.write()'s...
June 18, 2005, 3:02 AM

Search