/    Sign up×
Community /Pin to ProfileBookmark

Accessing Javascript file

I’ve got a page in the main folder of my site that uses the code in a .JS file. If I place the .JS file in my main folder with the webpage the webpage can see it, but if I put it in a subfolder it can’t. I’ve never had this problem before and I’m using the same code on other pages except the name of the .JS file is different. Any ideas?
Here’s my code that works:

[CODE]
<script type=”text/javascript” language=”JScript5.0″ src=”/ImageRotate.js”></script>
[/CODE]

But I want it to look like this:

[CODE]
<script type=”text/javascript” language=”JScript5.0″ src=”/Scripts/ImageRotate.js”></script>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManAug 20.2007 — when you specify a relative pathname that has a preceding forward slash, it assumes you want to "fire" the relative pathname from the root of your domain.

so for instance, you have a html page located here:

http://www.yourdomain.com/mywebsite/subdirectory/mypage.html

if mypage.html has a link to something like:

<img src ="/ImageRotate.gif">

it will assume the image is supposed to load from:

http://www.yourdomain.com/ [B](notice no more directories)[/B]

to give you a final URL of:

http://www.yourdomain.com/ImageRotate.gif

obviously, your image doesnt exist there, and it wont work. same for your JS file.

to fix this problem, you have to do one of two things which work exactly the same way: either add a dot before that slash to indicate that you want to load the content from the directory it is in directly, or remove the slash completely.

therefore, either of these will work from you.

understood relative to current directory pathname:

&lt;script type="text/javascript" language="JScript5.0" src="Scripts/ImageRotate.js"&gt;&lt;/script&gt;

implicit relative to current directory pathname:

&lt;script type="text/javascript" language="JScript5.0" src="./Scripts/ImageRotate.js"&gt;&lt;/script&gt;
Copy linkTweet thisAlerts:
@nbcrockettauthorAug 20.2007 — The path I wanted should have worked because it's the path from the root directory. I figured out what the problem was though. There was nothing wrong with the code. It ended up being a problem with the folder permissions. It's always the last thing you think to check! Thanks for your help.
×

Success!

Help @nbcrockett spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...