FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

HTML/Java Question

 


karysky
Hello,

I have a question, and I'll try to formulate it so you can understand my problem.

I use a javascript that just highlights a flag (France or England) when the mouse gets over it (to select French or English versions of my website). And I wonder if there is a way to put the script in one file and then access it with all my HTML pages, with an insert or something.

Because right now, the thing I do, is to copy paste the whole javascript on top of my every HTLM pages.. it's long, especially when I want to change a little detail.

Also, is it possible to do the same thing with HTML code? I use the same side bar on my every HTML page (Home, About me, My videos... etc etc) but instead of pasting it on my every page, is there a way to put it in a separate file and insert it somehow, on my pages? Because it's long again, especially when I want to add a section to my page... I have to add that section on all my 25 pages or so... I'd like to change it once, and then it applies to all my pages.

Thank you very much! I'd appreciate it if you could give me some code lines to copy paste!
TomS
Yeah, there is a way.

Make a new textfile "myscript.js" and copy the javascript code in to it.

Then in every html-file you need it, add the following codeline between the head-tags:

Code:
<script type="text/javascript" src="myscript.js" type="text/javascript"></script>


To your 2nd problem: No. Not with html. Use php.
For example you have index.htm and page2.htm; rename them into index.php and page2.php.

Then make a new file with the code you want to insert.

the php code is the following:
Code:
<? include "myinsert.htm"; ?>
karysky
TomS wrote:
Yeah, there is a way.

Make a new textfile "myscript.js" and copy the javascript code in to it.

Then in every html-file you need it, add the following codeline between the head-tags:

Code:
<script type="text/javascript" src="myscript.js" type="text/javascript"></script>


To your 2nd problem: No. Not with html. Use php.
For example you have index.htm and page2.htm; rename them into index.php and page2.php.

Then make a new file with the code you want to insert.

the php code is the following:
Code:
<? include "myinsert.htm"; ?>


Thank you very much, I'm going to try it right now.
mariohs
create a php file named header.php, and put your header information there (doctype declaration, title, keywords) and also the <script> tag with that... then, create all the other sections and include the header... it's basically the same solution the guy above gave you, but you can go further and modularize your entire site, with, menu.php, footer.php, and so on....

another solution:
a question: are the english and french flags a hyperlink?
if so, you don't need to use javascript to highlight the flag (i think there are 4 images over there, 2 grayscale and 2 colorfull), just the css woud do for you...
karysky
mariohs wrote:
create a php file named header.php, and put your header information there (doctype declaration, title, keywords) and also the <script> tag with that... then, create all the other sections and include the header... it's basically the same solution the guy above gave you, but you can go further and modularize your entire site, with, menu.php, footer.php, and so on....

another solution:
a question: are the english and french flags a hyperlink?
if so, you don't need to use javascript to highlight the flag (i think there are 4 images over there, 2 grayscale and 2 colorfull), just the css woud do for you...


Ok, I tried doing that but it didn't work... so I tried making a very simple page with .php but it didn't work either. Here's what I did:

test.php wrote:

<html>
<head>
<title></title>

</head>
<body>

This is a test!

</body>
</html>


and this is where I wanted to include that file:

index.php wrote:

<html>
<head>
<title></title>
</head>
<body>
<?
include "test.php";
?>
</body>
</html>



I don't know why it doesn't work... Hints anyone?
mariohs
try something like this....

Code:
test.php
<p>Hello World!</p>


Code:
index.php:
<html>
<head>
<title></title>
</head>
<body>
<?
require_once("test.php");
?>
</body>
</html>


I don't know if you got it...
that's one advantage of using php... you don't need to copy the whole html on the file you are including... just the part that interest to you...

let's suppose you have this message on all your pages... and then you want to change the message, just go there and change the "Hello World!" to another thing, and all the php files that includes it, are automatically "updated"
karysky
mariohs wrote:
try something like this....

Code:
test.php
<p>Hello World!</p>


Code:
index.php:
<html>
<head>
<title></title>
</head>
<body>
<?
require_once("test.php");
?>
</body>
</html>


I don't know if you got it...
that's one advantage of using php... you don't need to copy the whole html on the file you are including... just the part that interest to you...

let's suppose you have this message on all your pages... and then you want to change the message, just go there and change the "Hello World!" to another thing, and all the php files that includes it, are automatically "updated"


Mmmm doesn't work either.

I'll just keep things the way they are. I'll try to modularize my web page later, after learning PHP correctly.

Thanks anyway !
mariohs
I don't know why it's not working, it worked perfectly here...
btw, tell me you are testing this on the server and not on your machine Very Happy
karysky
mariohs wrote:
I don't know why it's not working, it worked perfectly here...
btw, tell me you are testing this on the server and not on your machine Very Happy



Confused


...... on the server ........


Holy crap, bloody hell !


Shocked

It works... Now I feel idiot... I'll try with my webpage now...
mariohs
@karysky

No big deal, man... such things always happens when you are trying it for the first time...

A little bit theory... extensions like php, asp, aspx, jsp, etc, etc, etc need an interpreter to "compile" them and show only the html output... it's not "flat" file, like html or txt that what's displayed is exactly what's in the file...
l
Related topics

Firefox Problem!
php/HTML pages question
N00b Java Question
What computer languages you know?
Stairway To Heaven - Satanic Subliminal Messages?

How about some feedback on site.
[Official] Best PHP Editor
auto Video File playing Page making script
Programming links, info, and tutorials
Most Unique/creative site you have visited

Hello
Czy tworzysz strony internetowe?
Justification for War in Iraq
Creating Roll-over Menus
Can somebody help me to make my site interactive
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

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