+ 1
A script written in a separate file is not executed
I created the .html and .js files in the same folder on my smartphone. Everything is as in the lesson, but the script is not executed. Why? What is missing? Я создал файлы .html и .js в одной папке на смартфоне. Всё как в уроке, но скрипт не выполняется. Почему? Чего не хватает?
10 Respostas
+ 4
Сергей Куликов It should work. Are you sure, both the html and js files are in the same folder?
+ 1
Hey Сергей Куликов, did you include your script in the html document? Just add the script tag after the body tag!
<body>
....
</body>
<script src="your-js-file-name.js"></script>
As long as you don't include the file, it won't work :))
+ 1
Сергей Куликов Here is an example :
alertBox.js (js file)
alert('Hi there, I am running!');
-----------------------
index.html (html file)
<html>
<head>
<!-- Do not include here -->
</head>
<body>
</body>
<script src="alertBox.js"></script>
<!-- Include the javascript file after the body tag -->
</html>
Now if you open, index.html in your browser, you'll get 'Hi there, I am running!' as an alert!
+ 1
Arb Rahim Badsa, n
itstill doesn't work. In the upper code I just tried the script working. Now html is.:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="text.js"></script>
</head>
<body>
</body>
</html>
and it doen't work
+ 1
ok i'm going to try it now...
+ 1
Arb Rahim Badsa, it still doesn't work. I'll figure it out later. Thank you for the help.
0
Arb Rahim Badsa, yes, sure. Everything is like in the lesson.
html file:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>alert("This is an alert box!");</script>
</head>
<body>
</body>
</html>
js file:
alert("This is an alert box!");
0
stop...
0
there is no file name. I guess I didn't save it.
0
Arb Rahim Badsa, yes I'm sure. I am busy now a little, maybe I have a mistake in my code. I'll do it later, thanks.