+ 2
"An external JavaScript cannot contain script tag" what does it mean?
Does it mean that the JavaScript code can be written in HTML without using script tag if this will we used as external .js file??
4 Respuestas
+ 5
In the.js file you do not need to start by writing <script> as though it was part of a HTML code.
+ 3
I would explain this with an example.
Suppose you had written some js in an HTML file.
<Head>
.....
<Script>
Alert('Js is working');
</Script>
...
Now if you have a lot of JavaScript then it is better to separate html and Js in different files.
1. Create a file with .js extension. Eg: test.js
2. Cut everything from inside of script tag, from the HTML file. And remove the script tag from HTML file.
3. Paste into the test.js and save.
4. Link the js file from the HTML
<Script SRC="test.js"></script>
assuming html and Js file are in the same directory.
5. Done.
Script tag is an html tag and JavaScript doesn't understand it, Script tag is used in an html file to write JavaScript. When you write your JavaScript in a separate file script tag is not required in the js file.
+ 1
Thanks
+ 1
Thanks