PDA

View Full Version : HTML Links in External File


SteveV24
12-10-2002, 12:45 AM
Hello,

I would like to use an external .js file for a list of HTML links that will be used on a number of pages. The idea is that I can edit this .js file and all of the calling pages will not have to be edited.

Can anyone give me an example of the code for the .js file as well as the calling HTML file?

Thanks!

CitznFish
12-10-2002, 12:59 AM
Originally posted by SteveV24
Hello,

I would like to use an external .js file for a list of HTML links that will be used on a number of pages. The idea is that I can edit this .js file and all of the calling pages will not have to be edited.

Can anyone give me an example of the code for the .js file as well as the calling HTML file?

Thanks!

From what i gather you want an external JS file to write in links that are the same on multiple pages..

Here is how I did it:

On your HTML pages include this code:

<!-- bottom global nav -->
<SCRIPT LANGUAGE="JavaScript" src="globalnav.js">
</script>

the external JS file should look like this... (basically a bunch of documnet.write's)

document.write('<table border="0" cellpadding="0" cellspacing="0" width="725"> ');
document.write(' <tr><td align="center" width="102"><spacer type="block" height="1" width="102"></td> ');
document.write(' <td align="center" width="520"><a href="http://familyfun.go.com/utilities/global/feature/SiteMap/">Site Map</a><!--&nbsp;&nbsp;&nbsp;<a href="http://disneyaffiliates.com/">Affiliate Program</a>-->&nbsp;&nbsp;&nbsp;<a href="http://psc.disney.go.com/guestservices/8440.html">Contact Us</a>&nbsp;&nbsp;&nbsp;<a href="http://familyfun.go.com/Register/">Register</a>&nbsp;&nbsp;&nbsp;<a href="http://familyfun.go.com/utilities/global/feature/Help/">Help</a>&nbsp;&nbsp;&nbsp;<a href="http://familyfun.go.com/utilities/global/feature/AboutUs/">About FamilyFun</a><br><div class="spacer8p"></div> ');
document.write(' ');
document.write(' ');
document.write('<a href="http://familyfun.go.com/utilities/global/feature/mfyhp_index/">Make FamilyFun Your Home Page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.dig.com/legal/wdig_privacy.html">Privacy</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://disney.go.com/legal/conditions_of_use.html">Legal</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://disney.go.com/legal/internet_safety.html">Internet Safety</a><div class="spacer8p"></div></webobject>&copy; FamilyFun. All rights reserved.<br><div class="spacer12p"></div> ');
document.write(' </td> ');
document.write(' ');
document.write(' <td align="center" width="103"><spacer type="block" height="1" width="103"></td> ');
document.write(' </tr> ');
document.write('</table> ');


I use 4 different external JS files to place identical code into 29,000 different web pages. In all the testing I have done it hasn't shown to decrease load times at all...


you can see this live at http://familyfun.go.com (the bottom footer)

SteveV24
12-10-2002, 05:40 PM
Perfect, just what I needed to get my site working with a Javascript file.

Thanks!!

zmoker
12-10-2002, 08:23 PM
But how can you make it display or not the in navigation for the page you're on?
Example: I change the font color of the page you are on as an indicator. How would you put in a function for that?
('if pageurl = document.writeurl
class="red"
else
class="black" ');
I also had a problem with a pop-up window in my nav bar so I took it out but wonder if there is a fix for that as it wasn't 'seeing' the eol
Thanks

zmoker
12-10-2002, 08:31 PM
The pop-up code is such:
<a href="javascript:PopUp('http://whatever.com/someplace/pic-archive.htm','620','440')">Pictures</a>
and entered it so:
document.write('<a href="javascript:PopUp('http://whatever.com/someplace/pic-archive.htm','620','440')">Pictures</a> ');

Any suggestions are appreciated

I do have another question about inserting a .js file inside a .js but will wait for some feedback from this.

Thanks in advance!

CitznFish
12-10-2002, 11:23 PM
Zmoker,

i am not sure what you are asking. Do you have a better example, or an you provide a more detailed description?

As for a JS file within a JS file. Don't bother, it's not a good idea.... :)

Graeme Hackston
12-11-2002, 03:41 AM
Originally posted by CitznFish
As for a JS file within a JS file. Don't bother, it's not a good idea.... :)

CitznFish could you explain what you mean by this? I'm presently loading a DOM js file from a non-Dom js file like this. Is it incorrect?

if(DomBrowser){
document.write('<\script src="Script_DOM.js" type="text/javas\cript"></s\cript>');
}else{
}

zmoker
12-12-2002, 09:23 PM
What I want to do is highlight in the navigation, from a js file, indicating which page you are currently on.

I am converting some big sites navigation over to this method (external .js file) but would like to keep the page indications intact.

Maybe the logic would be something like:
IF url of active page EQUALS a line item (nav link)
THEN display line item in red
ELSE
NEXT line item
IF line item EQUALS null
END.

Problem is I'm not sure how to define a line item and have it recognize a url and what the syntax would look like.
THANKS