2

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>
2
  • What OS are you using? Are you running a web server?
    – John Conde
    Commented Apr 15, 2011 at 18:54
  • I'm on a Mac...
    – Meltemi
    Commented Apr 15, 2011 at 19:08

1 Answer 1

1

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

2
  • Using /Users/meltemi/Sites/mysite/javascriptfile.js resolves to file:///Users/meltemi/Sites/mysite/javascriptfile.js on a Mac at least.
    – Meltemi
    Commented Apr 15, 2011 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
    Commented Apr 15, 2011 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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