Can't insert javascript file into html


#1

hello, I’m new in hml coding, try to insert javascript file into the code but it doesn’t work…
i have to say that if i open inner script its work ()
and also about styles so i can insert it without problems.
but if i try to attach file of javascript he jast not read it. no jquery and no my own file.

it is my demo code for see if its work:

15Game

and in scripts.js:

function openalert(){
alert(‘yoohoo’);
};

all the insert files is in the same package… any ideas?


#4
here is my html code..

<!DOCTYPE html>
<html>

<head>

<meta charset ="utf-8"/>
<title>15Game</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/css" src = "scripts/js"></script>

</head>

<body>

<script type="text/javascript">
openalert();
</script>
<body/>
</html>

#6

Try this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset ="utf-8"/>
    <title>15Game</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/css" src = "scripts/js"></script>
  </head>

  <body>
    <script>
      function openalert()
      {
        alert("yoohoo");
      }
      openalert();
    </script>
  </body>
</html>

Or this, but with a file .js

<!DOCTYPE html>
<html>
  <head>
    <meta charset ="utf-8"/>
    <title>15Game</title>
    <link rel="stylesheet" type="text/css" href="styles.css"/>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/css" src = "scripts/js"></script>
  </head>

  <body>
    <script src="text.js"></script>
  </body>
  
</html>

In this case the name of the file .js is text

function openalert()
{
  alert("yoohoo");
}
openalert();

#7

thank you for replay.
about your option 1:
i no have problem to make any code without external files, but i want to be able insert javascript files because i wanna use JQuery…

about option 2:
it doesn’t work… he just not read the file… i try to open the file in .js format in my comp and its say: Microsoft javascript runtime error: ‘windows’ is undefined.
but i don’t know what its mean… are you know if its related and if so,- how to fix?


#8

Please use clearer descriptive words in order to give us an unobscured mental picture of what’s going on for you. You opened a file “in your computer” and “it” said something. When there’s a JavaScript error about something being undefined, it usually means that there’s an attempt at using a variable without creating it first. Do you have the variable windows in your JavaScript file? Are you trying to use the global window?

<script type="text/css" src = "scripts/js"></script>

I’m not sure why you did this, but it doesn’t mean anything.