Log in

View Full Version : How to link javascript?



Gilbert0
10-12-2008, 04:58 PM
I used the Ultimate Fade-in slideshow (v1.51) (http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm) found in Dynamic Drive and implemented it in a site i have been working for the local volunteer center as part of a school project. Here is the site (http://friendshipvc.webs.com/index.htm)


I want to know if there is a way to save the java script as a .js file, load it to the server, and then link it in the head tag as opposed to writing it all. Then in the body, where you have to bring up the script, be able to do the following:

<script type="text/javascript" src="nameofthescript.js">

IS THIS POSSIBLE? IF IT IS, WHAT DO I NEED TO DO TO MY CODE?

codeexploiter
10-13-2008, 03:24 AM
Definitely it is possible. For that you can do the following steps:

1. Copy the JS code excluding the script tag (open/closing). In other words the JS file should not contain the script opening and closing tags, it is supposed to contain only JS code.

2. Insert the code in another file save it with an extension .js

3. In your Web page you can insert a script element that includes the newly created JS file in the following manner:


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

The thing you need to make sure is if the JS files is in the same folder of your web page then you can avoid specifying the 'filepath' otherwise you need to specify the correct path of the JS file for the inclusion.

Thats it, you are ready to start.

Hope this helps.

Gilbert0
10-13-2008, 10:00 PM
I tried exactly what codeexploiter told me but it didn't work. :confused:

Here is URL to the "test" page of the website--where I followed codeexploiter's instructions. (http://friendshipvc.webs.com/test.htm)

Please review my script file as well as my body coding.

Thanks for all of your help,
Gilbert0

bluewalrus
10-13-2008, 11:59 PM
The java your using is just forwarding the page to another page? You can do that with a meta tag.


<meta http-equiv="Refresh" content="#OF SECONDS TILL FORWARDING;http://www.sitenametoforwardto.com" />

You don't need the noscripts nor to link the file twice. No scripts are if javas turned off. Since theres nothing in it, it won't do anything. I'm assuming you were using the p file in the post.


<script src="http://www.freewebs.com/p.js"></script>

Gilbert0
10-16-2008, 12:24 AM
I tried removing all of scripts from the site and changed the
tagging on the http://friendshipvc.webs.com/imagescrip.js but
nothing.

I'll explain step-by-step what how I made the site, perhaps I'm
doing something wrong in the process.

1. I downloaded the java script form ....

2. I copy and paste the code (without the tags) onto an new text document.

2.1. After saving it with the same "imagesscript" i change the extension on it
to ".js"

3. I load the file into the main folder of the host/server right where the index.htm file is.

4. I add the corresponding script to the body of my site in the DIV where i want it to appear and tag it:
<script src="http://friendshipvc.webs.com/imagescrip.js"> ... </script>


I used the same tagging that I was told to use on this forum, but the script still doesn't show up the page.

Any suggestions?

HERE ARE MY FILES:
Javescript: http://friendshipvc.webs.com/imagescrip.js
PAGE: http://friendshipvc.webs.com/test.htm


I WOULD LIKE FOR THE TEST SITE TO SHOW THE SAME SCRIP AS IN MY HOME PAGE (http://friendshipvc.webs.com/index.htm) WITHOUT HAVING TO WRITE ALL OF THE JAVASCRIPT INSIDE THE <HEAD> TAG.

bokanegro
10-17-2008, 05:35 PM
Hi,

You have error!!!

Your java script must be placed in HEAD tags this is very inportant ! You just have to copy and past code from DD into notepad WITHOUT <script> tags, save like you wont

i.e. imagescript.js

Then in head of you page insert:


<script type="text/javascript" src="imagescript.js"></script>

After that do this: Where you wont to show images insert this code in your BODY tags


<script type="text/javascript">
new fadeshow(fadeimages, 758, 250, 0, 7000, 1, "R")
</script>

Note: This script doesn't work in IE 8 beta2, there is no fade transition

This will work for you!!!

Gilbert0
10-17-2008, 06:56 PM
I cannot thank you guys enough!

I have successfully re-written my code.

bokanegro
10-18-2008, 06:31 AM
I cannot thank you guys enough!

I have successfully re-written my code.

Don't thank us, just use RESOLVED button in your post, and help other users if they have same problem...