Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about linking the .js file

Status
Not open for further replies.

martinsafp

Technical User
Jul 10, 2001
7
0
0
NL
If i link the .js file like <script language=&quot;JavaScript&quot; src=&quot;scripts/filename.js&quot;> it doesn't work, if i put the file in the root directory and change the src, it still doesn't work. It only works if i put the whole script in the source of my page, but i want to link it. How should i do this?
 
Are you using </script> ?

<script language=&quot;JavaScript&quot; src=&quot;scripts/filename.js&quot;></script>

just an idea
 
What does your linked script look like?
- tleish
 
if i show the whole script, i will use very much space in this thread. But the script helps with some kind of alt on a link, like an alt on an image.
The server is casesensitive, but that's not the problem.
 
the script is:

var tmr=null;
var mov=false;
var txto=0;
var yoff=0;
var started=false;

function init(){
if(ie||ns){
mylayer=new Gl_layer(0,-100,10,&quot;&quot;);
if(ie) mylayer.ob.backgroundColor=&quot;#00BFFF&quot;;
else mylayer.ob.bgColor=&quot;#00BFFF&quot;;
mylayer.ob.borderColor=&quot;#1E90FF&quot;;
mylayer.ob.borderWidth=&quot;1px&quot;;
mylayer.ob.borderStyle=&quot;solid&quot;;
mymouse=Ms_initmouse();
started=true
}
}

function mo(txt){
if(ie5) yoff=document.body.scrollTop;
if(ie||ns){
pretxt=&quot;<table width=127 cellpadding=1 cellspacing=0 border=0><tr><td><font color=\&quot;#000000\&quot; face=\&quot;Arial\&quot; size=1>&quot;;
posttxt=&quot;</font></td></tr></table>&quot;;
windowheight=Gl_get_window_height();
windowwidth=Gl_get_window_width();
mylayer.write(pretxt+txt+posttxt);
txtheight=mylayer.height;
txtwidth=mylayer.width;
if(!mov) tmr=setInterval('follow()',25);
mov=true
}
window.status=txt
}

function mout(){
if(ie||ns){
mylayer.moveTo(-500,-500);
mov=false;
clearInterval(tmr);
txto=0
}
window.status=&quot;Martin's Animal-Foto-Page&quot;
}

function follow(){
var lleft=0;
var ltop=0;
if(ie&&(txto<80)){
txto+=5;
mylayer.ob.filter=&quot;alpha(opacity=&quot;+txto+&quot;)&quot;
}
if((mymouse.x+txtwidth+20)<windowwidth)
lleft=mymouse.x+5;
else
lleft=mymouse.x-(txtwidth+10);
if((mymouse.y+yoff+txtheight+30)<windowheight+yoff)
ltop=mymouse.y+yoff+20;
else
ltop=mymouse.y+yoff-(txtheight+5);
mylayer.moveTo(lleft,ltop)
}

var Sp_totalsprites=0;
Sp_xoffset=0;
Sp_yoffset=0;

var Gl_version=1.3;
var Gl_totalpreimages=0;
var Gl_interval=null;
var Gl_hooked=new Array();
var Gl_preimage=new Array();
var Gl_ticker=0;
var Gl_sin=new Array();
var Gl_cos=new Array();
var Gl_failure=false;
var Gl_cookies=new Array();
var Gl_layer_index=0;

var ie=false,ie5=false,ns=false,ns5=false,appleBrowser=false;
Gl_getbrowser();
Gl_makedegs();
Gl_get_cookies();

function Gl_getbrowser(){
var ua = navigator.userAgent.toLowerCase();
var ver = parseInt(navigator.appVersion);
if(ua.indexOf(&quot;msie&quot;)!=-1){
if(document.all) ie=true;
if(ua.indexOf(&quot;msie 5&quot;)!=-1)
ie5=true
}else if(ua.indexOf(&quot;mozilla&quot;)!=-1){
if(document.layers)
ns=true;
if(ns&&(ver>4)) ns5=true
}

if((ua.indexOf('macintosh')!=-1)||(ua.indexOf('ppc')!=-1)||(ua.indexOf('powerpc')!=-1))
appleBrowser=true;

if(!ns&&!ie&&!ns5&&!ie5)
Gl_failure=true
}

function Gl_preloader(img){var x=Gl_totalpreimages++;Gl_preimage[x]=new Image;Gl_preimage[x].src=img}
function Gl_hook(fnc){Gl_hooked[Gl_hooked.length]=fnc}
function Gl_unhook(fnc){var fnd=false;for(var n=0;n<Gl_hooked.length;n++) if(Gl_hooked[n]==fnc){fnd=true;break}if(fnd){for(var i=n;i<Gl_hooked.length-1;i++) Gl_hooked=Gl_hooked[i+1];Gl_hooked.length--}}
function Gl_start(){Gl_interval=setInterval(&quot;Sp_loop()&quot;,50)}
function Gl_stop(){clearInterval(Gl_interval)}
function Gl_makedegs(){for(n=0;n<360;n++){Gl_sin[n]=(Math.sin(3.14159*n/180));Gl_cos[n]=-(Math.cos(3.14159*n/180))}}
function Gl_get_cookies(){var tar=document.cookie.split(&quot;; &quot;);for(var n=0;n<tar.length;n++) Gl_cookies[n]=new Gl_Cookie_construct(tar[n])}
function Gl_Cookie_construct(Gl_var){var tmp=Gl_var.split(&quot;=&quot;);this.name=unescape(tmp[0]);this.value=unescape(tmp[1])}
function Gl_set_cookie(Gl_value){document.cookie=this.name+&quot;=&quot;+escape(Gl_value)+&quot;; expires= Wed, 1 May 2030 23:00:00 UTC; path=/&quot;;this.value=Gl_value;return true}
function Gl_delete_cookie(){for(var n=0;n<Gl_cookies.length;n++){if(Gl_cookies[n].name==this.name){this.value=null;document.cookie=this.name+&quot;=; expires= Mon, 3 Jan 2000 00:00:00 UTC; path=/&quot;;Gl_cookies[n].name=&quot;&quot;;Gl_cookies[n].value=&quot;&quot;;break}}return true}
function Gl_get_cookie(c_name){for(var n=0;n<Gl_cookies.length;n++){if(Gl_cookies[n].name==c_name){return Gl_cookies[n].value}}return null}
function Gl_cookie(Gl_name){this.name=Gl_name;this.value=Gl_get_cookie(Gl_name);this.setvalue=Gl_set_cookie;this.erase=Gl_delete_cookie}
function Gl_get_window_height(){if(ie) return windowheight=document.body.offsetHeight;else return windowheight=window.innerHeight}
function Gl_get_window_width(){if(ie) return windowwidth=document.body.offsetWidth;else return windowwidth=window.innerWidth}

function Gl_layer(Gl_xstart,Gl_ystart,Gl_w,Gl_html){
this.x=Gl_xstart;
this.y=Gl_ystart;
this.z=Gl_layer_index;
this.innerHTML=Gl_html;
this.width=Gl_w;
this.height=0;
if(ie){
document.body.insertAdjacentHTML(&quot;BeforeEnd&quot;,'<div id=&quot;Adiv'+Gl_layer_index+'&quot; style=&quot;position: absolute; left:'+Gl_xstart+'; top:'+Gl_ystart+'; width:'+Gl_w+'; visibility: visible&quot;>'+Gl_html+'</div>');
this.ob=document.all[&quot;Adiv&quot;+Gl_layer_index].style;
this.raw=document.all[&quot;Adiv&quot;+Gl_layer_index];
this.write=Gl_layerwriteIE;
this.append=Gl_layerappendIE;
this.moveTo=Gl_moveto;
this.setZ=Gl_setz;
this.clip=Gl_obclipIE;
}else{
this.ob=document.layers[Gl_layer_index]=new Layer(Gl_w);
document[&quot;Adiv&quot;+Gl_layer_index]=this.ob;
this.ob.name=Gl_layer_index;
this.ob.height=0;
this.ob.left=Gl_xstart;
this.ob.top=Gl_ystart;
this.ob.zIndex=Gl_layer_index;
this.ob.visibility=&quot;show&quot;;
this.raw=this.ob;
this.ob.document.open();
this.ob.document.write(Gl_html);
this.ob.document.close();
this.write=Gl_layerwriteNS;
this.append=Gl_layerappendNS;
this.moveTo=Gl_moveto;
this.setZ=Gl_setz;
this.clip=Gl_obclipNS;
}
this.Gl_index=Gl_layer_index;
Gl_layer_index++;
return this;
}

function Gl_layerwriteIE(Gl_txt){
this.raw.innerHTML=Gl_txt;
if(appleBrowser){
this.raw.style.height=0;
this.innerHTML=&quot;<div>&quot;+Gl_txt+&quot;\n</div>\n&quot;;
}
else
this.innerHTML=Gl_txt;

this.width=this.raw.clientWidth;
this.height=this.raw.clientHeight
}

function Gl_layerappendIE(Gl_txt,Gl_pos){if(Gl_pos && Gl_pos<this.innerHTML.length){var Gl_tmp=this.innerHTML.substring(0,Gl_pos)+Gl_txt+this.innerHTML.substring(Gl_pos,this.innerHTML.length);this.innerHTML=Gl_tmp;this.raw.innerHTML=Gl_tmp}else{this.innerHTML+=Gl_txt;this.raw.innerHTML=this.innerHTML}this.width=this.raw.clientWidth;this.height=this.raw.clientHeight}
function Gl_layerappendNS(Gl_txt,Gl_pos){if(Gl_pos && Gl_pos<this.innerHTML.length){var Gl_tmp=this.innerHTML.substring(0,Gl_pos)+Gl_txt+this.innerHTML.substring(Gl_pos,this.innerHTML.length);this.innerHTML=Gl_tmp}else this.innerHTML+=Gl_txt;this.ob.document.open();this.ob.document.write(this.innerHTML);this.ob.document.close();this.width=this.raw.clip.width;this.height=this.raw.clip.height}
function Gl_layerwriteNS(Gl_txt){this.ob.width=0;this.ob.height=0;this.ob.document.open();this.ob.document.write(Gl_txt);this.ob.document.close();this.innerHTML=Gl_txt;this.width=this.raw.clip.width;this.height=this.raw.clip.height}
function Gl_moveto(Gl_x,Gl_y){this.ob.top=Gl_y;this.ob.left=Gl_x;this.x=Gl_x;this.y=Gl_y}
function Gl_setz(Gl_z){this.ob.zIndex=Gl_z;this.z=Gl_z}
function Gl_get_heightIE(){return this.raw.clientHeight}
function Gl_get_heightNS(){return this.raw.clip.height}
function Gl_get_widthIE(){return this.raw.clientWidth}
function Gl_get_widthNS(){return this.raw.clip.width}
function Gl_obclipNS(Gl_left,Gl_right,Gl_top,Gl_bottom){this.ob.clip.left=Gl_left;this.ob.clip.right=Gl_right;this.ob.clip.top=Gl_top;this.ob.clip.bottom=Gl_bottom}
function Gl_obclipIE(Gl_left,Gl_right,Gl_top,Gl_bottom){this.ob.clip=&quot;rect(&quot;+Gl_top+&quot;,&quot;+Gl_right+&quot;,&quot;+Gl_bottom+&quot;,&quot;+Gl_left+&quot;)&quot;}

var Ms_m=new Ms_msobj;
Ms_mouseon=true; // information for sprite routines

function Ms_initmouse(){if(ns){document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP|Event.MOUSEDOWN);document.onMouseMove=Ms_getmousexy;document.onMouseDown=Ms_md;document.onMouseUp=Ms_mu}else{document.onmousemove=Ms_getmousexy2;document.onmousedown=Ms_md;document.onmouseup=Ms_mu}return Ms_m}
function Ms_mu(evnt){Ms_m.mousedown=false;Ms_m.dragging=false;if(Ms_m.over!=null){Ms_m.over.ob.zIndex=Ms_m.z;Ms_m.over.on=Ms_m.onstate;eval(Ms_m.over.onclickup);Ms_m.over=null}return true}
function Ms_md(evnt){Ms_m.mousedown=true;if(Ms_m.over!=null){eval(Ms_m.over.onclickdown);Ms_m.xoff=Math.floor(Ms_m.x-Ms_m.over.x);Ms_m.yoff=Math.floor(Ms_m.x-Ms_m.over.x);Ms_m.onstate=Ms_m.over.on;Ms_m.over.on=false;Ms_m.z=Ms_m.over.ob.zIndex;Ms_m.over.ob.zIndex=10000;return false}return true}
function Ms_getmousexy(evnt){Ms_m.x=evnt.pageX-Sp_xoffset;Ms_m.y=evnt.pageY-Sp_yoffset;if(Ms_mouseon){if(!Ms_m.mousedown) checkmo();else if(Ms_m.over!=null&&Ms_m.over.draggable){Ms_m.over.x=Ms_m.x-Ms_m.xoff;Ms_m.over.y=Ms_m.y-Ms_m.yoff;Ms_m.over.ob.left=Ms_m.x-Ms_m.xoff+Sp_xoffset;Ms_m.over.ob.top=Ms_m.y-Ms_m.yoff+Sp_yoffset;Ms_m.dragging=true}if(Ms_m.over!=null) return false}return true}
function Ms_getmousexy2(){Ms_m.x=event.clientX-Sp_xoffset;Ms_m.y=event.clientY-Sp_yoffset;if(Ms_mouseon){if(!Ms_m.mousedown) checkmo();else if(Ms_m.over!=null&&Ms_m.over.draggable){Ms_m.over.x=Ms_m.x-Ms_m.xoff;Ms_m.over.y=Ms_m.y-Ms_m.yoff;Ms_m.over.ob.left=Ms_m.x-Ms_m.xoff+Sp_xoffset;Ms_m.over.ob.top=Ms_m.y-Ms_m.yoff+Sp_yoffset;Ms_m.dragging=true}if(Ms_m.over!=null) return false}return true}
function checkmo(){Ms_m.over=null;var Ms_msfnd=-10000;for(var n=0;n<Sp_totalsprites;n++){var sp=Sp_sprite[n];if(sp.on&&(Ms_m.x>sp.x)&&(Ms_m.x<sp.x+sp.width)&&(Ms_m.y>sp.y)&&(Ms_m.y<sp.y+sp.height)&&(sp.z>Ms_msfnd)){Ms_m.over=sp;Ms_msfnd=sp.z}}if(Ms_m.over!=Ms_m.cover){if(Ms_m.cover!=null) eval(Ms_m.cover.onmouseout);if(Ms_m.over!=null) eval(Ms_m.over.onmouseover)}Ms_m.cover=Ms_m.over}
function Ms_msobj(){this.xoff=0;this.yoff=0;this.z=0;this.onstate=false;this.mousedown=false;this.dragging=false;this.lmd=null;this.x=0;this.y=0;this.over=null;this.cover=null;this.enable=Ms_enable;this.disable=Ms_disable}
function Ms_enable(){Ms_mouseon=true;}
function Ms_disable(){Ms_mouseon=false;if(Ms_m.over!=null) eval(Ms_m.over.onmouseout);if(Ms_m.cover!=null) eval(Ms_m.cover.onmouseout);Ms_m.over=null;Ms_m.cover=null}



it works fine this way, but if i link it, it fails!
 
I had the same problem before. It has nothing to do with the content of the script if you can run it on the same page of your htm, asp, etc file.

There're only two possibilities that I can think of.
1. Case sensitive issue. That you have already tried. What if you type the full URL of the js file on the browser. Can you download the js file?

2.If you use some web host like Yahoo that automatically generate some JavaScript on your page for advertisement. It might cause problem if there're overlapping object definition, etc...

I wouldn't pay too much attention to the content if it works the other way.

Regards
 
If your .js-file doesn´t work, if you put it in the root-directory, using
<script language=&quot;JavaScript&quot; src=&quot;filename.js&quot;></script>
I think the problem is that you have to initialize your script with a function in the head-tag and start the hole thing with <body onLoad &quot;initialize()&quot;>
My guess is that you should do it as followed:

<head>
<script language=&quot;JavaScript&quot; src=&quot;filename.js&quot;></script>
<script language=&quot;JavaScript&quot;>
<!--
function initialize(){
init()
}
-->
</script>
</head>
<body onLoad=&quot;initialize()&quot;>

Hope this works,
Detlef
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top