https://www.example.com/products/widget.html
| | | |
| | | +-- document
| | +-- directory
| + - server
+ - protocol
/products/widget.html
| |
| +-- document
+-- directory
widget.html
|
+-- document
<script> tags<head> or the <body><script> tag<h1>Testing alert</h1>
<script>
alert('hello!');
</script>
<button onclick="alert('Boom!');">DO NOT PRESS</button>
<script> tag can be used to import code from a separate file<script> tags in the external JavaScript file</script> tag is still required<h1>Testing alert</h1>
<script src="code/hello.js"></script>
src - location of JavaScript filetype - script type - default application/javascriptcharset - character encoding - default is UTF-8async - download file in the background, run once downloadeddefer - download file in the background, run it after page is loaded"use strict"; at the beginning of your file
<script> tag should go in the head sectiondefer attribute to prevent blockingtype attribute (JS is default)document.write() (it doesn't work with external JavaScript files!)<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>WEB230</title>
<script src="script.js" defer></script>
</head>
<body>
<h1>WEB230 - JavaScript</h1>
<p>I hate JavaScript</p>
</body>
</html>
'use strict';
let message = 'JavaScript is fun!';
console.log(message);
alert('ਜਾਵਾ ਸਕ੍ਰਿਪਟ ਮਜ਼ੇਦਾਰ ਹੈ!');
console.log('
');
document.querySelector('p').textContent = message;
running downloaded code is dangerous
JavaScript runs the code in a "sandbox"
browser prevents it from doing dangerous things
Most of the material presented is not from the chapter.