Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'm overlooking the obvious...Modifying an index page on local hard drive before uploading it to server. And the javascript is not loading. This doesn't work:

file:///Users/meltemi/Sites/mysite/index.html

But, when page is uploaded and served from Apache then the javascript works:

http://www.mysite.com/index.html

Site directories are identical both locally and on remote server. I have tried this with Safari 5.0.5 & Firefox 4.0.

code excerpts, though I don't believe it's a code issue:

<!DOCTYPE html>
<html lang="en">
<!--<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" media="screen" href="css/main.css" />
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script type="text/javascript"
     src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript" src="galleria/galleria-1.2.3.min.js"></script>

</head>
<body>
<header class="group">
    <div id="header-inner">
        <nav class="group">
                  ...
        </nav>
    </div>
</header>
<hr />
<script type="text/javascript">
    if (Galleria) { $("body").text('Galleria works') }
</script>
</body>
</html>
share|improve this question
    
What OS are you using? Are you running a web server? –  John Conde Apr 15 '11 at 18:54
    
I'm on a Mac... –  Meltemi Apr 15 '11 at 19:08

1 Answer 1

up vote 1 down vote accepted

You need to specify the full path including the drive. The file: part is unnecessary.

C:/Users/meltemi/Sites/mysite/javascriptfile.js

or *nix:

/Users/meltemi/Sites/mysite/javascriptfile.js

Ideally you'll develop in a web environment and then can use a path relative the webroot which will be the same regardless of whether the site is local or on the live server:

/javascripts/javascriptfile.js

share|improve this answer
    
Using /Users/meltemi/Sites/mysite/javascriptfile.js resolves to file:///Users/meltemi/Sites/mysite/javascriptfile.js on a Mac at least. –  Meltemi Apr 15 '11 at 19:07
    
Ah. i see what you're talking about... the http: got truncated at some point in my script src for jQuery. Dunno why it would work when being served by Apache?!? perhaps jQuery was cached?!? Ah well, silly mistake. Thanks for help! –  Meltemi Apr 15 '11 at 19:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.