You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like`alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui)of the tutorial.
So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`.
8
7
9
8
10
-
## The "script" tag
9
+
## تەگ ئێسکریپت
11
10
12
-
JavaScript programs can be inserted almost anywhere into an HTML document using the `<script>` tag.
13
-
14
-
For instance:
11
+
دەتوانرێت بەرنامەکانی جاڤاسکڕێپت لە نزیکەی هەر شوێنێکی بەڵگەنامەیەکی HTML دا بە بەکارهێنانی تاگی `<script>` دابنرێت.
15
12
16
13
```html run height=100
17
14
<!DOCTYPE HTML>
@@ -23,7 +20,7 @@ For instance:
23
20
24
21
*!*
25
22
<script>
26
-
alert( 'Hello, world!' );
23
+
alert( 'سڵاو ، جیهان' );
27
24
</script>
28
25
*/!*
29
26
@@ -35,53 +32,58 @@ For instance:
35
32
```
36
33
37
34
```online
38
-
You can run the example by clicking the "Play" button in the right-top corner of the box above.
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
47
53
48
-
The `type` attribute: <code><script <u>type</u>=...></code>
49
-
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial.
54
+
کۆمێنتەکانی پێش و دوای سکڕێپتەکە.
50
55
51
-
The `language` attribute: <code><script <u>language</u>=...></code>
52
-
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
53
56
54
-
Comments before and after scripts.
55
-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
Here,`/path/to/script.js`is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance,`src="script.js"`, just like`src="./script.js"`, would mean a file `"script.js"` in the current folder.
There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
0 commit comments