PDA

View Full Version : JS scripts


darkannie
03-07-2003, 09:38 AM
if you can change the layout of your entire website with one or two pages of format with casscading stylesheets, then does that mean that JS include scripts do the same thing with javascript. For example, you want all your link images to glow or swap without needing to code each and every page with mountains and mountains of code just just write all your javascript in one page and include it? this is basically my assertion, because i read on another HTML guide website that you can use JS script include to display a menu of links on all your pages, needing only to change the one page. well, i got to work straight away ... and failed every method i tried. nothing worked till i tried shtml includes that did EXACTLY what i was trying with the JS script includes. Plus i went comparison shopping to many different sites incorporating JS includes, and CSS includes. first off, NO ONE was using them to display their menu of links, the JS scripts i downloaded had nothing but javascript code in them. i just need to know ... was that website wrong or did i do something wrong? i asked this on another message board and got no responses, i tried subscribing to a javascript message board to ask them, but they NEVER sent off the email i needed to complete my registration. somebody please PLEASE answer this question. I would love to know how to make JS includes work, and how to make the JS files. i keep getting different demonstrations no matter where i go.

speedracer
03-07-2003, 12:06 PM
see if you can understand this thread:
http://www.codingforums.com/ubb/Forum6/HTML/000973.html

i would use combination of .js include(javascript include would be in the serverside include or the entire <head> and or <body>tag) and server side include(php,asp,etc.) like the shtml. same principle with css.

beetle
03-07-2003, 12:07 PM
First of all, using SSI is a much prefereable method to generate re-sued HTML pieces vs. using JS to do the same.

External JS files are simple. They are just text files with javascript code in them, often given the extension '.js'. In these JS files, you don't insert any native HTML markup, including the opening and closeing <script> tags. An example JS file with a simple functionfuncton helloWorld()
{
alert( 'Hello World!' );
}That's it, the whole file right there. Let's save it as 'hello.js'.

Now, to use that, we must include it into our html page.<script type="text/javascript" src="js/hello.js"></script>Now, where do we put this <script> tag? Well, it can go pretty much anyplace, but it belongs in the <head><html>
<head>
<title>Hello World</title>
<script type="text/javascript" src="js/hello.js"></script>
</head>

<body>
Blah blah blah
</body>
</html>So, now our HTML page has the 'hello.js' file included (note: this page assumes that 'hello.js' is in a relative subfolder named 'js')

All we need to do now is call our function!<body onload="helloWorld()">or, use whatever event you'd like :D