Help - Search - Members - Calendar
Full Version: Referencing a js page
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
arcticwanderer
Hello

This should be a simple thing but I can't get it right. If you look at the source on my website www.montagnaphotography.com I have a js code in the body that begins with the following:

<script>
/*****************************************************************************
Default browsercheck - Leave this one
******************************************************************************/
function lib_bwcheck(){ //Browsercheck (needed)
this.ver=navigator.appVersion; this.agent=navigator.userAgent .........</script>

The script works fine but is long and I want to cut it out of the body and put on a seperate page. I've cut it out, put it as a js.script file and tried referencing it using several codes such as: <script src="http://www.montagnaphotography.com/scripts.js" type=text/javascript></SCRIPT> without any luck. Does anyone have a suggestion how to reference the script correctly?
Christian J
Could you provide a test page that shows the problem?
pandy
Additionally, does your browser throw an error (turn debugging on if you haven't already)? Did you leave the script tags in when you copied the code to a separate file?
Frederiek
An url was already provided: http://www.montagnaphotography.com

There is no javascript error, but the HTML does have errors when passing the page through the WDG validator. Some are related to the script element. Start by fixing those first.

For instance, you have:
<script language=JavaScript1.2 src="coolmenus3.js">">

The correct syntax is:
<script type="text/javascript" src="coolmenus3.js"></script>

(be sure to quote attribute properties, that goes for all attribute values in HTML tags too)

Other script elements in the page don't have a TYPE.

See the HTMLreference for the script element

You can link to the different scripts by adding as many such script elements to the page, eg. one for each functionality by copying the script in a text file, like you did for coolmenus3.js. Leave the legal comments together with the corresponding scripts. Then, if someone takes the code, the legal notice will be included with a reference to the original site of that script.
pandy
QUOTE(Frederiek @ Jun 23 2007, 10:56 AM) *

An url was already provided: http://www.montagnaphotography.com

Christian tricked me. blush.gif
Frederiek
Must be a swedish thing then biggrin.gif
Christian J
QUOTE(Frederiek @ Jun 23 2007, 10:56 AM) *

An url was already provided: http://www.montagnaphotography.com

No, I meant a test page of the thing that didn't work. On the page above the script is still embedded.
pandy
That wasn't clear. rolleyes.gif

QUOTE(Frederiek @ Jun 23 2007, 11:48 AM) *

Must be a swedish thing then biggrin.gif

I'm so gullible! blush.gif
Frederiek
Christian, the OP did cut out the coolMenus script by Thomas Brattli (http://www.dhtmlcentral.com/coolmenus/). As I suggested, the same thing can be done for the other scripts taken from elsewhere too. Or it might be that the script doesn't work in a certain browser (which?). I didn't get any error in Safari.

Pandy, no harm done wink.gif
Christian J
Now you're confusing me Fredriek, it's pandy that should be confused. tongue.gif

QUOTE(Frederiek @ Jun 23 2007, 01:00 PM) *

As I suggested, the same thing can be done for the other scripts taken from elsewhere too.

Agreed, but unless the OP shows an example of what didn't work we can't say what went wrong. The OP did post this example:

CODE
<script src="http://www.montagnaphotography.com/scripts.js" type=text/javascript></SCRIPT>

which looks OK to me.
pandy
QUOTE(Christian J @ Jun 23 2007, 03:06 PM) *

Now you're confusing me Fredriek, it's pandy that should be confused. tongue.gif

Sometimes your mission fails. IPB Image
arcticwanderer
QUOTE(Christian J @ Jun 22 2007, 04:07 PM) *

Could you provide a test page that shows the problem?


Here is a test page
www.montagnaphotography.com/baba. This will pull up the index to a folder I've called baba. As you can see the menu is gone. The scripts.js file is in the folder so it should work, but doesn't. You can look at that file by typing in : www.montagnaphotography.com/baba/scripts.js. The folder is a copy of the www.montagnaphotography.com/editorial page folder that has the js script still on the page and works fine. This tag : <script language=JavaScript1.2 src="coolmenus3.js"> works fine referencing the coolmenus3.js file so I don't understand why the other tag doesn't.

Thanks alot.
Christian J
CODE
<script language=JavaScript1.2 src="coolmenus3.js">
<script language=JavaScript src="scripts.js">

These two need a closing </script> tag each.
arcticwanderer
Thanks, that seems to do the trick. That's the problem with cutting and pasting, things get left out.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.