homepage Welcome to WebmasterWorld Guest from 54.237.134.62
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Creating external javascripts
external javascripts
mrw770




msg:971479
 8:05 pm on Apr 17, 2003 (gmt 0)

I found a really great free javascript to replace the menus on my website, but would like to make it into an external js file so I don't have to hard-code it onto every page anymore. I've done this for a basic drop-down script before, but this one has two parts: one for the head section and one for the body of my HTML page. Do I need to break this into two files with references in each part (if so, I must be doing it wrong) or is there some other trick to it? Or do I just need to find a simpler script and scrap this plan? If needed, I can post the script here (it's pretty long). Thanks for any help you can give!

 

oilman




msg:971480
 8:12 pm on Apr 17, 2003 (gmt 0)

externalize the part the goes in the head section - that's the functional part of the code. The code in the body is what uses the funtions of the part in the head and needs to stay in the page. I'm guessing a little bit here since I don't know exactly how you're setup but I think that's usually the case.

oh - and welcome to WebmasterWorld :)

mrw770




msg:971481
 8:35 pm on Apr 17, 2003 (gmt 0)

Thanks - it worked! And thanks for the welcome. :)

gcross




msg:971482
 10:26 pm on Apr 17, 2003 (gmt 0)

When I use external javascript files for menus, copyrights, updated lines, etc., this is the code I use:

<script type="text/javascript" language="Javascript" src="filename.js">
</script>

This goes into the BODY into the appropriate placement and does not need to be echoed in the HEAD section. Then the file named filename.js contains the content.

To create it is pretty easy. Insert your content into the main document and format it until it looks the way you want it. Then remove that code, complete with formatting codes and put it into the filename.js file and add in the necessary javascript changes into the .JS file and the <script> command into the .HTML file. I generally rely on the
document.write (" ");
command line for my external .JS file. Don't forget to comment out the quotes that are a part of the navigation, with a backslash (\), like
document.write ("<a href=\"filename.htm\"></a>");

And to make sure the spiders and Linux users are not completely confounded by the javascript menus, I try to have at least the index page containing the menus unadulterated by javascript.

grahamstewart




msg:971483
 11:16 pm on Apr 17, 2003 (gmt 0)

I found a really great free javascript to replace the menus on my website

I'd just like to emphasise what gcross pointed out - if you use javascript for all your menus then people with javascript turned off will not be able to navigate your site, and neither will spiders.

Make sure you supply an alternative means of navigation - or consider using CSS instead of Javascript to make pretty looking menus (depends what you want it to do really, but CSS can handle all the usual prety hover effects).

grahamstewart




msg:971484
 11:20 pm on Apr 17, 2003 (gmt 0)

Oh.. and if you are writing a page using html that validates [validator.w3.org] to a recent doctype (and you should be!), then omit the language="Javascript" tag, it has been deprecated.

ShawnR




msg:971485
 2:00 am on Apr 18, 2003 (gmt 0)

"...Don't forget to comment out the quotes that are a part of the navigation, with a backslash (\), like
document.write ("<a href=\"filename.htm\"></a>"); ..."

It is a good idea to get in the habit of using one set of quotes for html and the other for javascript. For example:

document.write ('<a href="filename.htm"></a>');

You still might need to escape quotes from time to time, depending on the context, but much less often, and the code will be easier to read and debug.

Shawn

g1smd




msg:971486
 1:00 pm on Apr 20, 2003 (gmt 0)

Make sure that you provide a normal HTML link to your sitemap page, and that the sitemap page has normal HTML links to every other page of your site. This helps both search engines which cannot follow javascript links, as well as users who have turned off javascript in their browser, or who never had it installed in the first place.

You also need to escape the / of the closing </a> tag, and of any other closing tags, by changing to this format: <\/a> instead.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved