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
The tutorial that you're reading is about core JavaScript, which is platform-independent. Further on, you will learn Node.JS and other platforms that use it.
3
+
Dieses Tutorial behandelt Java-Script, im Kern eine plattformunabhängige Technik. Später wenden wir uns Node.js und anderen Plattformen zu die JavaScript verwenden.
4
4
5
-
But, we need a working environment to run our scripts, and, just because 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. On the other hand, browser details are explained in detail in the [next part](/ui)of the tutorial.
5
+
Doch zunächst benötigen wir eine Umgebung in der wir unsere Scripte ausführen können. Da dies ein Online-Buch ist, liegt es nahe, den Browser zu verwenden. Wir vermeiden so weit als möglich browserspezifische Anweisungen (wie`alert`) so dass Sie keine Zeit darauf verlieren, wenn ihr späteres Augenmerk eigentlich Node.js sein soll. Interessieren Sie sich aber für die Browserdetails, so behandeln wir diese ausführlich im [nächsten Teil](/ui)des Tutorials.
6
6
7
-
So first, let's see how to attach a script to a webpage. For server-side environments, you can just execute it with a command like `"node my.js"`for Node.JS.
7
+
Fangen wir aber damit an, wie man ein Script in eine Webseite einbettet. Befinden Sie sich in einer serverseitigen Umgebung können Sie ein Script mit einem Kommando wie `"node my.js"`mit Node.js ausführen.
8
8
9
9
10
-
## The "script" tag
10
+
## Das "script"-Tag
11
11
12
-
JavaScript programs can be inserted in any part of an HTML document with the help of the `<script>` tag.
12
+
JavaScript-Programme können überall innerhalb eines HTML-Dokuments mit Hilfe des `<script>`-Tags platziert werden.
13
13
14
-
For instance:
14
+
Zum Beispiel:
15
15
16
16
```html run height=100
17
17
<!DOCTYPE HTML>
18
18
<html>
19
19
20
20
<body>
21
21
22
-
<p>Before the script...</p>
22
+
<p>Vor dem Script...</p>
23
23
24
24
*!*
25
25
<script>
26
26
alert( 'Hello, world!' );
27
27
</script>
28
28
*/!*
29
29
30
-
<p>...After the script.</p>
30
+
<p>...Nach dem Script.</p>
31
31
32
32
</body>
33
33
34
34
</html>
35
35
```
36
36
37
37
```online
38
-
You can run the example by clicking on the "Play" button in its right-top corner.
38
+
Sie können die Beispiele in diesem Tutorial laufen lassen, indem Sie den "Play"-Knopf in der oberen rechten Ecke anklicken.
39
39
```
40
40
41
-
The`<script>` tag contains JavaScript code which is automatically executed when the browser meets the tag.
41
+
Das`<script>`-Tag beinhaltet JavaScript-Code der automatisch ausgeführt wird, wenn der Browser den Tag erreicht.
42
42
43
+
## Der moderne Dialekt
43
44
44
-
## The modern markup
45
+
Das `<script>`-Tag besitzt einige Attribute die heute nicht mehr eingesetzt werden, die man aber in älterem Code finden kann:
45
46
46
-
The `<script>` tag has a few attributes that are rarely used nowadays, but we can find them in old code:
The `type` attribute: <code><script <u>type</u>=...></code>
49
+
Der alte HTML4-Standard sah vor, dass Scripte einen Typ haben müssen, typischerweise `type="text/javascript"`. Der aktuelle HTML-Standard nimmt diesen Typ als Standardwert an; eine Angabe des Attributes ist nicht notwendig.
49
50
50
-
: The old standard HTML4 required a script to have a type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type` by default. No attribute is required.
The `language` attribute: <code><script <u>language</u>=...></code>
53
-
: This attribute was meant to show the language of the script. As of now, this attribute makes no sense, the language is JavaScript by default. No need to use it.
53
+
Dieses Attribut sollte die Programmiersprache des Scripts anzeigen. Da diese standardmäßig JavaScript ist, gibt es keine Notwendigkeit das Attribut zu verwenden.
54
54
55
-
Comments before and after scripts.
56
-
: In really ancient books and guides, one may find comments inside `<script>`, like this:
57
-
58
-
```html no-beautify
59
-
<script type="text/javascript"><!--
60
-
...
61
-
//--></script>
62
-
```
63
-
64
-
These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. We mention it here, because such comments serve as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.
55
+
**Kommentare vor und nach Scripten**
65
56
57
+
In sehr alten Anleitungen, Büchern und Codes findet man Kommentare innerhalb von `<script>`, so wie diesen:
58
+
```html no-beautify
59
+
<scripttype="text/javascript"><!--
60
+
...
61
+
//--></script>
62
+
```
66
63
67
-
## External scripts
64
+
Solche Kommentare sollten den Script-Code vor älteren Browsern verstecken, die mit dem `<script>`-Tag noch nichts anfangen konnten. Aber alle Browser aus mindestens den letzten 15 Jahren haben dieses Problem nicht. Wir zeigen dieses Idiom hier als ein Warnzeichen. Wenn Sie es irgendwo entdecken, können Sie davon ausgehen, dass der Code wirklich sehr alt ist und es sich nicht lohnt, sich näher damit zu befassen.
68
65
69
-
If we have a lot of JavaScript code, we can put it into a separate file.
66
+
## Externe Scripte
70
67
71
-
The script file is attached to HTML with the `src` attribute:
68
+
Wenn wir sehr viel JavaScript-Code auf unserer Seite haben, können wir diesen in einer separaten Datei platzieren. Die Datei wird mit dem `src`-Attribute zur HTML-Webseite hinzugefügt:
72
69
73
70
```html
74
-
<scriptsrc="/path/to/script.js"></script>
71
+
<scriptsrc="/pfad/zum/script.js"></script>
75
72
```
76
73
77
-
Here `/path/to/script.js`is an absolute path to the file with the script (from the site root).
74
+
`/fad/zum/script.js`ist eine absolute Pfadangabe zur Script-Datei, ausgehend vom Wurzelverzeichnis der Seite.
78
75
79
-
It is also possible to provide a path relative to the current page. For instance, `src="http://github.com/script.js"`would mean a file `"script.js"`in the current folder.
76
+
Alternativ können auch relative Pfade angegeben werden. Zum Beispiel heißt `src="http://github.com/script.js"`das eine Datei `"script.js"`im aktuellen Ordner verwendet werden soll.
Mehrere Scripte können mit mehreren `script`-Tags geladen werden:
88
85
89
86
```html
90
87
<scriptsrc="/js/script1.js"></script>
@@ -93,29 +90,23 @@ To attach several scripts, use multiple tags:
93
90
```
94
91
95
92
```smart
96
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
97
-
98
-
The benefit of a separate file is that the browser will download it and then store in its [cache](https://en.wikipedia.org/wiki/Web_cache).
93
+
Nur die aller einfachsten Scripte sollten direkt in eine HTML-Datei geschrieben werden. Komplexere Dinge landen in einer eigenen Datei.
99
94
100
-
After this, other pages that want the same script will take it from the cache instead of downloading it. So the file is actually downloaded only once.
101
-
102
-
That saves traffic and makes pages faster.
95
+
Ein Vorteil davon ist, dass Browser diese Dateien in ihrem [Cache](https://de.wikipedia.org/wiki/Cache) vorhalten, nachdem sie einmal geladen wurden. Verwendet eine andere Seite das selbe Script, kann dieses aus dem Cache genommen werden und muss nicht nochmal aus dem Web geladen werden. Das spart Web-Traffic und beschleunigt Seiten.
103
96
```
104
97
105
-
````warn header="If`src`is set, the script content is ignored."
106
-
A single`<script>` tag can't have both the `src` attribute and the code inside.
98
+
````warn header="Wenn`src`gesetzt wurde, wird der Inhalt von `<script>` ignoriert."
99
+
Ein einzelner`<script>`-Tag kann kein `src`-Attribute und JavaScript-Code beinhalten.
107
100
108
-
This won't work:
101
+
Das hier würde nicht funktionieren:
109
102
110
103
```html
111
104
<script*!*src*/!*="file.js">
112
-
alert(1); //the content is ignored, because src is set
105
+
alert(1); //Der Inhalt wird ignoriert, das src verwendet wird
113
106
</script>
114
107
```
115
108
116
-
We must choose: either it's an external `<script src="…">` or a regular `<script>` with code.
117
-
118
-
The example above can be split into two scripts to work:
109
+
Wir können das Beispiel in zwei Scripte aufteilen um es lauffähig zu machen:
119
110
120
111
```html
121
112
<scriptsrc="file.js"></script>
@@ -125,11 +116,10 @@ The example above can be split into two scripts to work:
125
116
```
126
117
````
127
118
128
-
## Summary
129
-
130
-
- We can use a `<script>` tag to add JavaScript code to the page.
131
-
- The `type` and `language` attributes are not required.
132
-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
119
+
## Zusammenfassung
133
120
121
+
- Wir können das `<script>`-Tag verwenden um JavaScript-Code zu einer Webseite hinzuzufügen.
122
+
- Die Attribute `type` und `language` werden nicht länger benötigt.
123
+
- Ein Script aus einer anderen Datei kann mit `<script src="pfad/zum/script.js"></script>` geladen werden.
134
124
135
-
There is much more to learn about browser scripts and their interaction with the web-page. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves from it. We'll be using a browser as a way to run JavaScript, which is very convenient for online reading, but yet one of many.
125
+
Es gibt noch viel mehr über Scripte im Browser und deren Interaktion mit Webseiten zu sagen. In diesem Teil des Tutorials soll es aber nur um die Sprache JavaScript gehen und wir wollen uns davon zunächst nicht ablenken. Wir nutzen den Browser zunächst als eine bequeme Möglichkeit um JavaScript-Code ablaufen zu lassen.
0 commit comments