신수용

10 JavaScript for Web Broswer

1 +<html>
2 +<head>
3 +<script type="text/javascript">
4 +function message(){
5 +alert("This alert box was called with the onload event");
6 +}
7 +</script>
8 +</head>
9 +
10 +<body onload="message()">
11 +<script type="text/javascript">
12 +document.write("This message is written by JavaScript");
13 +</script>
14 +</body>
15 +
16 +</html>
1 +<html>
2 +<head>
3 +<script type="text/javascript" src="xxx.js"></script>
4 +
5 +<script type="text/javascript">
6 +function message(){
7 +alert("This alert box was called with the onload event");
8 +}
9 +</script>
10 +</head>
11 +
12 +<body onload="message()">
13 +</script>
14 +</body>
15 +
16 +</html>
1 +<html>
2 +<head>
3 +</head>
4 +
5 +<body>
6 +<script type="text/javascript">
7 +
8 +var str="Hello world!";
9 +//look for "Hello"
10 +var patt=/Hello/g;
11 +var result=patt.exec(str);
12 +document.write("Returned value: " + result);
13 +
14 +//look for "W3Schools"
15 +patt=/W3Schools/g;
16 +result=patt.exec(str);
17 +document.write("<br />Returned value: " + result);
18 +
19 +
20 +</script>
21 +
22 +</body>
23 +
24 +</html>
1 +<html>
2 +<head>
3 +</head>
4 +
5 +<body>
6 +
7 +<script type="text/javascript">
8 +// location
9 +
10 +
11 +location.assign("http://www.google.com"); // ּ ̵
12 +
13 +
14 +</script>
15 +
16 +</body>
17 +
18 +</html>
1 +<html>
2 +<head>
3 +</head>
4 +
5 +<body>
6 +
7 +<script type="text/javascript" src="alert.js">
8 +</script>
9 +
10 +</body>
11 +
12 +</html>
1 +//window객체는 window. 생략 가능
2 +alert("test"); // 메시지 창 띄움
3 +
4 +window.open('','','width=200,height=100') // 새창 띄우기
5 +
6 +if (confirm("Are you sure?")) {
7 + // Yes/No를 묻는 다이얼로그 창 띄움. Yes일 때만 true
8 +}
9 +
10 +var name = prompt("Enter name"); // 사용자의 입력 받는 창 띄움
11 +
1 +document.write("This message is written by JavaScript");