FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to load external text and html?





tatorhead
What I'm trying to do is have a bit of code on all of my pages that loads text/html from a common file, which I can update and have all the pages update as well.

Any ideas on what do here?
neomax
Make use of scripting languages like php , Especially php templates Cool
Chris Tiaens
If you can't use server side scripting like php, you could also use javascript. Like this:

Code:


<html>

<head>
<title></title>

</head>

<body>

<script language="JavaScript" type="text/javascript" src="content.js"></script>

</body>

</html>




content.js :
Code:


document.write('html content here');



By adding '<script language="JavaScript" type="text/javascript" src="content.js"></script>' on all of your pages you can add the same content.
tatorhead
Thank you, that is exactly what I wanted
samr_vene
Hey is can that code be done with pictures? How would it be done?

Also lets say i want to make it a list(example, a navigation list). How would i do this using javascript instead of php.

Thanks.
prillan
Thx i needed that to m8! Very Happy
tatorhead
You really don't know how much you saved my life Chris
Summer
Quote:
Hey is can that code be done with pictures? How would it be done?

Also lets say i want to make it a list(example, a navigation list). How would i do this using javascript instead of php.

Thanks.


You must be making a template . Here's an example of code u shud use :

this is the codes i made for my templates :

Code:
//=================================================
// Navigation block in every page
//=================================================
// NOTE : Lines that started with // will not be read by browser , no edit is require
//=================================================
// Template :
//
//   document.write('<a href="link_to.html">text</a>');
//   
// Use the template (above) for one link ONLY . If you wanna add more , add in different line
// eg:
//   document.write('<a href="link_to.html">text</a>');
//   document.write('<a href="link_to.html">text</a>');
//=================================================
// Do not edit the line that is not between the // Start Edit and // End Edit .
//=================================================

document.write('<span class="genmed" style="line-height:150%">');

// Start Edit

document.write('<a href="index.html">Index</a><br />');

document.write('<a href="forum.html">Forum</a><br />');

document.write('<a href="download.html">Download</a><br />');

document.write('<a href="members.html">Members</a><br />');

document.write('<a href="help.html">Help</a><br />');

// End Edit

document.write('</span>');



Just use document.write(''); to write a line (1 line only) by following HTML format .

For image , it is the same :
Code:

document.write('<img src="link_to.image"></img>');
document.write('<img src="link_to.image2"></img>');


Save the file as navigation.js or anything that ends with .js then use this :

Code:
<script language="JavaScript" type="text/javascript" src="navigation.js"></script>


then place the code in every page so that u dun have to write the codes over and over again . You knew this too .

Hope this helps .
tatorhead
OK I am trying this now, and it doesnt seem to work.

my menu.js:

Code:
document.write('
<form name="jump">
<select name="menu"

onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">
<option value="http://sdfgh">asdrf</option>
<option value="http://sdfgh">sdfgh</option>
<option value="http://sedgfh">asdfgh</option>
<option value="sdfgh">sfdg</option>
<option value="sdgfhj">fdgh</option>
</select>
</form>');




My index.html:
Code:

<html>
<body>
<script language="JavaScript" type="text/javascript" src="menu.js">
</script>
</body>
</html>



But yet, this doesn't work. Any ideas?
pudovkin
I think you have a problem with quotation marks.
Try putting a slash before or after the marks, like:
Code:
document.write('
<form name=/"jump/">
Marston
... You guys do know that your menu won't show up if the user has Javascript disabeled, don't you?
LukeakaDanish
Marston wrote:
... You guys do know that your menu won't show up if the user has Javascript disabeled, don't you?


Which kinda removes the point in using a static, text-only menu? i wouldnt be too hard to write it with PHP...im not very skilled but i'll give it a go...

Code:

<?php

$menuStartString = '<form name="jump"><select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">'."/n";

$option1 = '<option value="http://sdfgh">asdrf<\/option>'."/n";
$option2 = '<option value="http://sdfgh">asdrf<\/option>'."/n";
$option3 = '<option value="http://sdfgh">asdrf<\/option>'."/n";
$option4 = '<option value="http://sdfgh">asdrf<\/option>'."/n";

echo ($menuStartString.$option1.$option2.$option3.$option4);

?>



Save this as Menu.php

Code:


<?php
include($_SERVER['DOCUMENT_ROOT'].'/menu.php');
?>



Include this in your documents.

With a bit of luck it should work Smile

Luke
KHO
lf you just want to include a file on each page, then just edit that one file, all you have to use is <?php include(URL); ?> and then it will call the document to the page as if you had written it there originally Neutral this way you only need to edit one document to change each page. l found this very usefull for my image map that l use on my site, whenever l need to add another link, l just change the image, and a few coordinates on the document, easy as that.
Marston
LukeakaDanish wrote:

Code:

<?php

$menuStartString = '<form name="jump"><select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">'."/n";

$option1 = '<option value="http://sdfgh">asdrf<\/option>'."/n";
$option2 = '<option value="http://sdfgh">asdrf<\/option>'."/n";
$option3 = '<option value="http://sdfgh">asdrf<\/option>'."/n";
$option4 = '<option value="http://sdfgh">asdrf<\/option>'."/n";

echo ($menuStartString.$option1.$option2.$option3.$option4);

?>

You totally over-complicated this part of the script. Regular HTML would work just fine in this instance...
tatorhead
KHO wrote:
lf you just want to include a file on each page, then just edit that one file, all you have to use is <?php include(URL); ?> and then it will call the document to the page as if you had written it there originally Neutral this way you only need to edit one document to change each page. l found this very usefull for my image map that l use on my site, whenever l need to add another link, l just change the image, and a few coordinates on the document, easy as that.



I ended up going with the php include after learning about it on the other forum
Summer
Quote:
document.write('
<form name="jump">
<select name="menu"

onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">
<option value="http://sdfgh">asdrf</option>
<option value="http://sdfgh">sdfgh</option>
<option value="http://sedgfh">asdfgh</option>
<option value="sdfgh">sfdg</option>
<option value="sdgfhj">fdgh</option>
</select>
</form>');


Your problem is : I told you , use document.write(''); for 1 line only . This shud be the file .

Code:

document.write('<form name="jump">');
document.write('<select name="menu" onChange="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO">');
document.write('<option value="http://sdfgh">asdrf</option>');
document.write('<option value="http://sdfgh">sdfgh</option>');
document.write('<option value="http://sedgfh">asdfgh</option>');
document.write('<option value="sdfgh">sfdg</option>');
document.write('<option value="sdgfhj">fdgh</option>');
document.write('</select>');
document.write('</form>');
Related topics
AJAX tutorial
PHP Tutorials
HOWTO?$lang files!
Firefox does not like my webpage...
rollovers in CSS
Message boards
Loading time?
Master Tutorial on SEO
css en html bestand, maar er gebeurd niks..
apply text to multiple html-pages?
Changing internal data with scripting.
Apache
How can I convert a DOM back to HTML?
Is there a simple way to convert a DOM back to HTML?
Reply to topic    Frihost Forum Index -> Webmaster and Internet -> Design Tips

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.