0

I am new to javascript and am trying to get this to work. When I link to my external .js file from my HTML it doesn't work, but when I enter the script directly in the HTML file, it works. I am sure that the src link I have given in the HTML is correct. I have checked it multiple times. I have both my linked .js files in the same folder as my HTML file.

This is the index.html file:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <title>Radar chart</title>
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script src="RadarChart.js"></script>
    <style>
        body {
          overflow: hidden;
          margin: 0;
          font-size: 14px;
          font-family: "Helvetica Neue", Helvetica;
        }

        #chart {
          position: absolute;
          top: 50px;
          left: 100px;
        }   
    </style>
  </head>
  <body>
    <div id="body">
      <div id="chart"></div>
    </div>

    <script type="text/javascript" src="script.js"></script>

  </body>
</html>

The error I am getting is as follows:

   file:///home/******/*****/Tempelates/Test/script.js Failed to load resource: net::ERR_FILE_NOT_FOUND

I am using Linux. I have already looked at the following questions, but they could not help me.

Javascript files not working when linked, but work internally?

javascript file not working when linked from HTML

Javascript not working with HTML external link

I have been breaking my head over this. Help would be much appreciated. Thanks.

EDIT The code works fine in Windows but not in linux. I am even more confused now.

13
  • Does your server serve static files in that directory? Commented Mar 24, 2015 at 15:15
  • RadarChart.js is in the same directory, I'm assuming? Commented Mar 24, 2015 at 15:15
  • 2
    are you sure path is correct for js file ? Commented Mar 24, 2015 at 15:15
  • How are you accessing the html file? just opeing it from the file system, or is it being served by a webserver (either locally or on the internet) Commented Mar 24, 2015 at 15:16
  • 1
    if you are using Google Chrome, Ctrl + Shift + I will bring up the developer box. You can check if your script is loaded by looking at "network" tab (Ctrl + Shift + R to clear cache). If you are using firefox, You can use firebug to locate the problem. Commented Mar 24, 2015 at 15:32

4 Answers 4

0

Are you using Google Chrome? I fixed my problem with the solution from here:
Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found

I think you have already solved this by now, but for what matters I've had the same problem on Google chrome and I did the following to fix it:

  1. Choose Customize and Control Google Chrome (the button in the up, right corner)
  2. Choose Settings
  3. Extensions
  4. Unmark all the extensions there. (they should show as Enable instead of Enabled) Regards,
Sign up to request clarification or add additional context in comments.

Comments

0

Since you're using Linux, make sure you have read/write permission to all the files and folders you're working with. That can cause these types of problems.

2 Comments

I checked that I have all the permissions.
If you still have not solved this issue and you really have to, I suggest that you post your script.js and RadarChart.js files here or make a jsfiddle or somehting. There might be something wrong within the code that is causing the problem. That way we can play with the full code to see what is causing the issue.
0

you want to check if the script.js is in the same folder as the html is , if not then you need to use the path to get to that folder and then reference the javascript file.

1 Comment

I am sure that script.js is in the same folder.
0

The answer is by OP. It was an extremely stupid mistake and I had stored the name of "script.js" incorrectly. I had stored it as "srcipt.js". I had made separate files in windows and copied the code there, instead of copying the files, that is why it worked there.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.