Skip to content

Commit cf00efd

Browse files
committed
js in html
1 parent 19041e7 commit cf00efd

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
| [clojurescript - hello](./examples/clojurescript/hello.html) | |
2929
| [coffeescript - tutorial](./examples/coffeescript/tutorial) | |
3030
| [Create React App - (jsx, flow)](./examples/my-app/build) | |
31+
| [JS in HTML](./examples-js-in-html.html) | A webpage with several inline scripts |
3132
| [asm.js](./examples/asm.html) | |
3233
| [wasm](./examples/wasm/fib/fib.index.html)||
3334

examples/js-in-html.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<html>
2+
<head>
3+
<script type="text/javascript">
4+
var globalObject = {
5+
first: 'name',
6+
last: 'words',
7+
};
8+
function sayHello(name) {
9+
return `Hello, ${name}!`;
10+
}
11+
</script>
12+
<style>
13+
BODY {
14+
font-size: 48px;
15+
color: rebeccapurple;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<h1>Testing Script Tags in HTML</h1>
21+
<script>
22+
const capitalize = name => {
23+
return name[0].toUpperCase() + name.substring(1);
24+
};
25+
const greetAll = ['my friend', 'buddy', 'world']
26+
.map(capitalize)
27+
.map(sayHello)
28+
.join('\n');
29+
30+
globalObject.greetings = greetAll;
31+
</script>
32+
<p>
33+
Some arbitrary intermediate content to affect the offsets of the scripts
34+
</p>
35+
<script>
36+
(function iife() {
37+
const greeting = sayHello('Ryan');
38+
console.log(greeting);
39+
})();
40+
</script>
41+
</body>
42+
</html>

0 commit comments

Comments
 (0)