Solved

Help needed for relative path to external js file

Posted on 2004-08-04
9
636 Views
Last Modified: 2008-03-17
This sounds pretty simple however it didn't work for me. I have an external js file myjscript.js in /home/js. I have a mypage.htm in /home/myfile/dir1
In the mypage.htm body I need to include the external js file. I used

<script language="javascript" src="../../js/myjscript.js"></script>

When I opened the htm page in browser, it couldn't locate the js file. What's wrong here? I don't want to use absolute path. Can anyone shed some light on this?? Thank you!
0
Comment
Question by:iLvChopin
9 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 11718219
Your example is correct. You have anywere else a typo.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11718340
I just simulated your example on my server and it worked!
You have a typo.
0
 

Author Comment

by:iLvChopin
ID: 11719238
I double checked and there is no typo. Again this js file was included in the body of the htm page not in between the header tag. I think the relative path is correct but the page can't find the js file.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 19

Expert Comment

by:dakyd
ID: 11719322
Zvonko's right ... the example you posted should work fine.  Try a quick test - add this as the very first line of your external js:
alert("found the external js");

If you see the alert, the file is linked properly.  If not, there's a different problem with your page.  Hope that helps.
0
 

Accepted Solution

by:
iLvChopin earned 0 total points
ID: 11719812
OK I figured out what's wrong. It is the double quotes and single quotes messed up issue cause it is within other script sentence. Thanks.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11719920
Typo ;-)
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11721408
Note that it's sometimes easier (and clearer) to just use the local absolute path of the script file, such as:

    <script language="javascript" src="/home/js/myjscript.js"></script>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

1 Experts available now in Live!

Get 1:1 Help Now