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
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Show an alert with an external script
5
+
# Vis en advarsel med gennem et eksternt script
6
6
7
-
Take the solution of the previous task <info:task/hello-alert>. Modify it by extracting the script content into an external file `alert.js`, residing in the same folder.
7
+
Tag din løsning fra før <info:task/hello-alert>. Tilret det, så du trækker JavaScript koden ud til en ekstern fil kaldet `alert.js` og som er placeret i samme folder som html-dokumentet.
8
8
9
-
Open the page, ensure that the alert works.
9
+
Åbn side for at sikre dig, at dialogboksen stadig vises.
This part of the tutorial is about core JavaScript, the language itself.
3
+
Denne del af tutorialen er om ren JavaScript, selve komponenterne i sproget.
4
4
5
-
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.
5
+
Men, du behøver et miljø til at afvikle dine scripts og siden denne bog er en online bog, så er browseren et godt bud. Jeg vil holde browser-specifikke kommandoer (som`alert`) til et minimum. Det gør jeg, hvis du f.eks. læser dette for at arbejde i andre miljøer (som f.eks. Node.js). Jeg vil fokusere på JavaScript i browseren i den [næste del](/ui)af tutorialen.
6
6
7
-
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"`.
7
+
Først, lad os se, hvordan du kobler et script til en webside. For server-side miljøer som Node.js, kan du afvikle scripts med kommandoen`"node my.js"`.
8
8
9
9
10
-
## The "script" tag
10
+
## "script" tagget
11
11
12
-
JavaScript programs can be inserted into any part of an HTML document with the help of the`<script>` tag.
12
+
JavaScript programmer kan blive sat ind i alle dele af et HTML-dokument ved hjælp af et`<script>` tag.
13
13
14
-
For instance:
14
+
For eksempel:
15
15
16
16
```html run height=100
17
17
<!DOCTYPE HTML>
@@ -35,53 +35,53 @@ For instance:
35
35
```
36
36
37
37
```online
38
-
You can run the example by clicking the "Play" button in the right-top corner of the box above.
38
+
Du kan køre eksemplet ved at klikke på "Play" i øverste højre hjørne.
39
39
```
40
40
41
-
The `<script>`tag contains JavaScript code which is automatically executed when the browser processes the tag.
41
+
`<script>`tagget indeholder JavaScript kode, der automatisk bliver afviklet når browseren processerer det.
42
42
43
43
44
-
## Modern markup
44
+
## Moderne markup
45
45
46
-
The `<script>`tag has a few attributes that are rarely used nowadays but can still be found in old code:
46
+
`<script>`tagget har et par egenskaber (kaldet attributes) der sjældent bruges mere, men du kan stadig finde dem i ældre kode:
47
47
48
-
The `type` attribute: <code><script <u>type</u>=...></code>
49
-
: The old HTMLstandard, 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.
: Den gamle HTML-standard, HTML4, krævede at et script beskrev sin `type`. Normalt var den sat til `type="text/javascript"`. Det er ikke påkrævet mere. Samtidig har den moderne HTML-standard helt ændret meningen med den attribut. Nu, kan den bruges til f.eks. JavaScript moduler, men det er et sværere emne, og jeg dækker moduler i et andet afsnit senere.
50
50
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.
: Denne attribut var ment til at vise sproget koden blev skrevet i. Denne attribut giver ikke længere mening fordi JavaScript er standardsproget i browseren.
53
53
54
-
Comments before and after scripts.
55
-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
54
+
Kommentarer før og efter scripts.
55
+
: I virkelig gamle bøger og guides kan du finde kommentarer inde i `<script>` tags, i stil med dette:
56
56
57
57
```html no-beautify
58
58
<script type="text/javascript"><!--
59
59
...
60
60
//--></script>
61
61
```
62
62
63
-
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.
63
+
Dette trick bruges ikke i moderne JavaScript. Disse kommentar tegn (<!-- og -->) skjulte JavaScript fra ældre browsere, der endnu ikke vidste hvodan man afviklede `<script>` tag. Siden browsere i de seneste 15 år ikke har haft problemer med dette, kan det hjælpe dig med at identificere virkelig gamle eksempler.
64
64
65
65
66
-
## External scripts
66
+
## Eksterne scripts
67
67
68
-
If we have a lot of JavaScript code, we can put it into a separate file.
68
+
HVis du har meget JavaScript kode, kan du placere det i en ekstern fil.
69
69
70
-
Script files are attached to HTML with the`src`attribute:
70
+
Script-filer bliver knuttet til HTML gennem en`src`attribut:
71
71
72
72
```html
73
73
<scriptsrc="/path/to/script.js"></script>
74
74
```
75
75
76
-
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"`would mean a file `"script.js"`in the current folder.
76
+
Her er `/path/to/script.js`en absolut sti til scriptet fra sitets rod. Du kan også give en relativ sti fra det aktuelle HTML-dokument. F.eks. betyder`src="script.js"`at filen `"script.js"`findes i samme folder som HTML-dokumetet.
Hvis du vil koble flere eksterne scripts til dokumentet skal du bruge flere tags:
85
85
86
86
```html
87
87
<scriptsrc="/js/script1.js"></script>
@@ -90,29 +90,29 @@ To attach several scripts, use multiple tags:
90
90
```
91
91
92
92
```smart
93
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
93
+
Som regel er det kun meget simple scripts der skrives direkte i HTML. Mere komplekse scripts placeres i eksterne filer.
94
94
95
-
The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
95
+
En fordel ved eksterne filer er, at browseren vil downloade dem og gemme dem i sin [cache](https://en.wikipedia.org/wiki/Web_cache).
96
96
97
-
Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
97
+
Andre dokumenter der referer til den samme fil vil så læse den fra chachen i stedet for at downloade det igen.
98
98
99
-
That reduces traffic and makes pages faster.
99
+
Det sparer trafik og gør siden hurtigere.
100
100
```
101
101
102
-
````warn header="If`src`is set, the script content is ignored."
103
-
A single`<script>` tag can't have both the `src`attribute and code inside.
102
+
````warn header="Hvis`src`er sat vil indholdet af `<script>` tagget blive ignoreret."
103
+
Et enkelt`<script>` tag kan ikke både have en `src`attribut og egen kode i sig.
104
104
105
-
This won't work:
105
+
Dette vil ikke virke:
106
106
107
107
```html
108
108
<script*!*src*/!*="file.js">
109
-
alert(1); //the content is ignored, because src is set
109
+
alert(1); //Indholdet ignoreres fordi src er sat
110
110
</script>
111
111
```
112
112
113
-
We must choose either an external`<script src="…">`or a regular `<script>`with code.
113
+
Du må vælge enten eksternt med`<script src="…">`eller internt `<script>`med kode i.
114
114
115
-
The example above can be split into two scripts to work:
115
+
Eksemplet ovenfor kan blive delt op i to scripts for at virke:
116
116
117
117
```html
118
118
<scriptsrc="file.js"></script>
@@ -122,11 +122,11 @@ The example above can be split into two scripts to work:
122
122
```
123
123
````
124
124
125
-
## Summary
125
+
## Opsummering
126
126
127
-
- We can use a `<script>` tag to add JavaScript code to a page.
128
-
- The `type` and `language` attributes are not required.
129
-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
127
+
- Du bruger et `<script>` tag til at tilføje JavaScript til et HTML-dokument.
128
+
- `type` og `language` attributter er ikke længere påkrævet.
129
+
- Et eksternt script kan blive knyttet til dokumentet med `<script src="path/to/script.js"></script>`.
130
130
131
131
132
-
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.
132
+
Der er meget mere at lære om browser scripts og deres interaktion med selve websiden. Men husk, at denne del af tutorialen har fokus på JavaScript sproget, så jeg vil ikke forvirre med for mange browser-specifikke emner. Du vil bruge en browser som en måde at afvikle JavaScript, som passer godt med denne online bog. Men, det er kun en af mange måder JavaScript kan afvikles.
0 commit comments