๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
IT/HTML

[34์ผ์ฐจ] 10์žฅ ์œˆ๋„์šฐ์™€ ๋ธŒ๋ผ์šฐ์ € ๊ด€๋ จ ๊ฐ์ฒด

by GWLEE 2022. 8. 5.

๐Ÿ’›2022-08-05๐Ÿ’›

 

ex10-1.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์œˆ๋„์šฐ ์—ด๊ธฐ</title>
<script>
function load(URL) {
	window.open(URL, "myWin", "left=300,top=300,width=400,height=300");
}
</script>
</head>
<body>
<h3>window.open()์œผ๋กœ ์œˆ๋„์šฐ ์—ด๊ธฐ</h3>
<hr>
<a href="javascript:load('http://www.graceland.com')">
         ์—˜๋น„์Šค ํ”„๋ ˆ์Šฌ๋ฆฌ ํ™ˆ ํŽ˜์ด์ง€</a><br>
<a href="javascript:load('http://www.universalorlando.com')">
         ์œ ๋‹ˆ๋ฒ„์„ค ์˜ฌ๋žœ๋“œ ํ™ˆ ํŽ˜์ด์ง€</a><br>
<a href="javascript:load('http://www.disneyworld.com')">
         ๋””์ฆˆ๋‹ˆ์›”๋“œ ํ™ˆ ํŽ˜์ด์ง€</a><br>
</body>
</html>

 

ex10-2.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์œˆ๋„์šฐ ๋‹ซ๊ธฐ</title>
<script>
let newWin=null; // ์ƒˆ๋กœ ์—ฐ ์œˆ๋„์šฐ ๊ธฐ์–ต
function load(URL) {
	newWin = window.open(URL, "myWin", "left=300,top=300,width=400,height=300");
}
function closeNewWindow() {
	if(newWin==null || newWin.closed) // ์œˆ๋„์šฐ๊ฐ€ ์—ด๋ฆฌ์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ๋‹ซํžŒ ๊ฒฝ์šฐ
		return; // ์œˆ๋„์šฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ๊ทธ๋ƒฅ ๋ฆฌํ„ด
	else
		newWin.close(); // ์—ด์–ด ๋†“์€ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ
}
</script>
</head>
<body>
<h3>window์˜ close()๋กœ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ</h3>
<hr>
<a href="javascript:load('http://www.disneyworld.com')">
         ์ƒˆ ์œˆ๋„์šฐ ์—ด๊ธฐ(๋””์ฆˆ๋‹ˆ์›”๋“œ)</a><br>
<a href="javascript:window.close()">
         ํ˜„์žฌ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ</a><br>
<a href="javascript:closeNewWindow()">
         ์ƒˆ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ</a>
</body>
</html>

ex10-3.html

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์œˆ๋„์šฐ ๋‹ซ๊ธฐ</title>
<script>
let newWin=null; // ์ƒˆ๋กœ ์—ฐ ์œˆ๋„์šฐ ๊ธฐ์–ต
function load(URL) {
	newWin = window.open(URL, "myWin", "left=300,top=300,width=400,height=300");
}
function closeNewWindow() {
	if(newWin==null || newWin.closed) // ์œˆ๋„์šฐ๊ฐ€ ์—ด๋ฆฌ์ง€ ์•Š์•˜๊ฑฐ๋‚˜ ๋‹ซํžŒ ๊ฒฝ์šฐ
		return; // ์œˆ๋„์šฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ๊ทธ๋ƒฅ ๋ฆฌํ„ด
	else
		newWin.close(); // ์—ด์–ด ๋†“์€ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ
}
</script>
</head>
<body>
<h3>window์˜ close()๋กœ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ</h3>
<hr>
<a href="javascript:load('http://www.disneyworld.com')">
         ์ƒˆ ์œˆ๋„์šฐ ์—ด๊ธฐ(๋””์ฆˆ๋‹ˆ์›”๋“œ)</a><br>
<a href="javascript:window.close()">
         ํ˜„์žฌ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ</a><br>
<a href="javascript:closeNewWindow()">
         ์ƒˆ ์œˆ๋„์šฐ ๋‹ซ๊ธฐ</a>
</body>
</html>

 

ex10-4.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>setInterval()๋กœ ํ…์ŠคํŠธ ํšŒ์ „</title></head>
<body>
<h3>ํ…์ŠคํŠธ๊ฐ€ ์ž๋™ ํšŒ์ „ํ•˜๋ฉฐ, ๋งˆ์šฐ์Šค๋กœ ํด๋ฆญํ•˜๋ฉด ์ค‘๋‹จํ•ฉ๋‹ˆ๋‹ค.</h3>
<hr>
<div><span id="span" style="background-color:yellow">
		์ž๋™ ํšŒ์ „ํ•˜๋Š” ํ…์ŠคํŠธ์ž…๋‹ˆ๋‹ค.</span>
</div>
<script>
let span = document.getElementById("span");
let timerID = setInterval("doRotate()", 200); // 200๋ฐ€๋ฆฌ์ดˆ ์ฃผ๊ธฐ๋กœ doRotate() ํ˜ธ์ถœ

span.onclick = function (e) { // ๋งˆ์šฐ์Šค ํด๋ฆญ ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ
	clearInterval(timerID); // ํƒ€์ด๋จธ ํ•ด์ œ. ๋ฌธ์ž์—ด ํšŒ์ „ ์ค‘๋‹จ
}

function doRotate() {
	let str = span.innerHTML;
	let firstChar = str.substr(0, 1);
	let remains = str.substr(1, str.length-1);
	str = remains + firstChar;
	span.innerHTML = str; // str ํ…์ŠคํŠธ๋ฅผ span ๊ฐ์ฒด์— ์ถœ๋ ฅ
}
</script>
</body>
</html>

 

ex10-5.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์œˆ๋„์šฐ์˜ ์œ„์น˜์™€ ํฌ๊ธฐ ์กฐ์ ˆ</title>
</head>
<body>
<h3>์œˆ๋„์šฐ์˜ ์œ„์น˜์™€ ํฌ๊ธฐ ์กฐ์ ˆ</h3>
<hr>
<button onclick="window.moveBy(-10, 0)">left</button>
<button onclick="window.moveBy(10, 0)">right</button>
<button onclick="self.moveBy(0, -10)">up</button>
<button onclick="moveBy(0, 10)">down</button>
<button onclick="resizeBy(10, 10)">+</button>
<button onclick="resizeBy(-10, -10)">-</button>
</body>
</html>

 

ex10-6.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์›น ํŽ˜์ด์ง€์˜ ์ž๋™ ์Šคํฌ๋กค</title>
<script>
function startScroll(interval) {
	setInterval("autoScroll()", interval);
}

function autoScroll() {
	window.scrollBy(0,10); // 10ํ”ฝ์…€ ์œ„๋กœ ์Šคํฌ๋กค
}
</script>
</head>
<body onload="startScroll(1000)">
<h3>์ž๋™ ์Šคํฌ๋กค ํŽ˜์ด์ง€</h3>
<hr>
<h3>๊ฟˆ๊ธธ(์ด๋™์ˆœ)</h3>
๊ฟˆ๊ธธ์—<br>
๋ฐœ์ž์ทจ๊ฐ€ ์žˆ๋‹ค๋ฉด<br>
๋‹˜์˜ ์ง‘ ์ฐฝ๋ฐ–<br>
๊ทธ ๋Œ๊ณ„๋‹จ ๊ธธ์ด ์ด๋ฏธ ์˜ค๋ž˜ ์ „์—<br>
๋ชจ๋ž˜๊ฐ€ ๋˜๊ณ  ๋ง์•˜์„ ๊ฑฐ์˜ˆ์š”<br><br>
ํ•˜์ง€๋งŒ<br>
๊ทธ ๊ฟˆ๊ธธ์—์„œ ์ž์ทจ ์—†๋‹ค ํ•˜๋‹ˆ<br>
๋‚˜๋Š” ๊ทธ๊ฒƒ์ด ์ •๋ง ์„œ๋Ÿฌ์›Œ์š”<br><br>
์ด ๋ฐค๋„<br>
๋‚˜๋Š” ๋‹˜์˜ ์ง‘ ์ฐฝ๋ฐ–<br>
๊ทธ ๋Œ๊ณ„๋‹จ ์œ„์— ํ™€๋กœ ์„œ์„œ<br>
ํ˜น์‹œ๋ผ๋„ ๋‹˜์˜ ๋ชฉ์†Œ๋ฆฌ๊ฐ€ ๋“ค๋ ค์˜ฌ๊นŒ<br>
๊ณ ๊ฐœ ์ˆ™์ด๊ณ  ์—ฟ๋“ค์–ด์š”<br>
</body>
</html>

 

ex10-7.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์›น ํŽ˜์ด์ง€ ํ”„๋ฆฐํŠธ</title>
</head>
<body>
<h3>์›น ํŽ˜์ด์ง€ ํ”„๋ฆฐํŠธ</h3>
<hr>
<p>window ๊ฐ์ฒด์˜ print() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด
window ๊ฐ์ฒด์— ๋‹ด๊ฒจ ์žˆ๋Š” ์›น ํŽ˜์ด์ง€๊ฐ€ ํ”„๋ฆฐํŠธ ๋ฉ๋‹ˆ๋‹ค.
<p>
<a href="javascript:window.print()">์ด๊ณณ์„ ๋ˆ„๋ฅด๋ฉด ํ”„๋ฆฐํŠธ ๋ฉ๋‹ˆ๋‹ค.</a><p>
<input type="button" value="ํ”„๋ฆฐํŠธ" onclick="window.print()">
</body>
</html>

 

ex10-8.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onbeforeprint์™€ onafterprint</title>
<style>
#logoDiv {
 	display : none;
	position : absolute; left : 0; top : 0;
	width : 100%; height : 100%;
	z-index : -1; /* ๋กœ๊ณ  ์ด๋ฏธ์ง€๋ฅผ ๋ฌธ์„œ์˜ ๋ฐ‘๋ฐ”๋‹ฅ์— ๋ฐฐ์น˜ */
}
</style>
<script>
window.onbeforeprint=function (e) {
	let logoDiv = document.getElementById("logoDiv");
	logoDiv.style.display = "block"; // block์œผ๋กœ ๋ณ€๊ฒฝ. ๋กœ๊ณ ๊ฐ€ ํ™”๋ฉด์— ๋‚˜ํƒ€๋‚˜๊ฒŒ ํ•จ
}
window.onafterprint=hideLogo;
function hideLogo() {
	let logoDiv = document.getElementById("logoDiv");
	logoDiv.style.display = "none"; // ๋กœ๊ณ ๋ฅผ ๋ณด์ด์ง€ ์•Š๊ฒŒ ํ•จ
}
</script></head>
<body>
<h3>onbeforeprint, onafterprint ์ด๋ฒคํŠธ ์˜ˆ</h3>
<hr>
<div id="logoDiv">
	<img src="media/logo.png" alt="์ด๋ฏธ์ง€ ์—†์Šต๋‹ˆ๋‹ค.">
</div>
<p>์•ˆ๋…•ํ•˜์„ธ์š”. ๋ธŒ๋ผ์šฐ์ € ์œˆ๋„์šฐ์—์„œ๋Š” ๋ณด์ด์ง€ ์•Š์ง€๋งŒ, ํ”„๋ฆฐํŠธ์‹œ์—๋Š” ํšŒ์‚ฌ ๋กœ๊ณ ๊ฐ€ ์ถœ๋ ฅ๋˜๋Š” ์˜ˆ์ œ๋ฅผ
๋ณด์ž…๋‹ˆ๋‹ค. ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ธ์‡„ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๋ฉ”๋‰ด๋ฅผ ์„ ํƒํ•ด ๋ณด์„ธ์š”.</p>
</body>
</html>

 

ex10-9.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>window.location์œผ๋กœ ์›น ์‚ฌ์ดํŠธ ์ ‘์†</title>
<script>
function load() {
	let select = document.getElementById("site");
	window.location=select.options[select.selectedIndex].value;
}
</script>
</head>
<body>
<h3>window.location์œผ๋กœ ์›น ์‚ฌ์ดํŠธ ์ ‘์†</h3>
<hr>
์‚ฌ์ดํŠธ ์„ ํƒ :
<select id="site">
	<option value="http://www.naver.com" selected>๋„ค์ด๋ฒ„
	<option value="http://www.google.com">๊ตฌ๊ธ€
	<option value="http://www.microsoft.com">๋งˆ์ดํฌ๋กœ์†Œํ”„ํŠธ
</select>
<p>
<button onclick="load()">์›น ์‚ฌ์ดํŠธ ์ ‘์†</button>
</body>
</html>

 

ex10-10.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>๋ธŒ๋ผ์šฐ์ € ์ •๋ณด ์ถœ๋ ฅ</title>
<style>
span { color : blue; }
div {
	border-color : yellowgreen;
	border-style : solid;
	padding : 5px;
}
</style>
<script>
function printNavigator() {
	let text = "<span>appCodeName</span>: " + navigator.appCodeName + "<br>";
		text += "<span>appName</span>: " + navigator.appName + "<br>";
		text += "<span>appVersion</span>: " + navigator.appVersion + "<br>";
		text += "<span>platform</span>: " + navigator.platform + "<br>";
		text += "<span>product</span>: " + navigator.product + "<br>";
		text += "<span>userAgent</span>: " + navigator.userAgent +"<br>";
		text += "<span>vendor</span>: " + navigator.vendor +"<br>";
		text += "<span>language</span>: " + navigator.language + "<br>";
		text += "<span>onLine</span>: " + navigator.onLine + "<br>";
		text += "<span>cookieEnabled</span>: " + navigator.cookieEnabled + "<br>";
		text += "<span>javaEnabled()</span>:" + navigator.javaEnabled() + "<br>";
		text += "<span>plugins.length</span>: " + navigator.plugins.length + "<br>";
		for(let j=0; j<navigator.plugins.length; j++) {
			text += "plugins" + j + " : <blockquote>";
			text += navigator.plugins[j].name + "<br>";
			text += "<i>" + navigator.plugins[j].description + "</i><br>";
			text += navigator.plugins[j].filename + "</blockquote>";
		}

	// div ํƒœ๊ทธ์— ์ถœ๋ ฅ
	let div = document.getElementById("div");
	div.innerHTML = text;
}
</script>
</head>
<body onload="printNavigator()">
<h3>๋ธŒ๋ผ์šฐ์ €์— ๊ด€ํ•œ ์ •๋ณด ์ถœ๋ ฅ</h3>
์•„๋ž˜์— ์ด ๋ธŒ๋ผ์šฐ์ €์— ๊ด€ํ•œ ์—ฌ๋Ÿฌ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค.
<hr>
<p>
<div id="div"></div>
</body>
</html>

 

ex10-11.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์Šคํฌ๋ฆฐ์— ๊ด€ํ•œ ์ •๋ณด ์ถœ๋ ฅ</title>
<script>
function printScreen() {
	let text = "availHeight:" + screen.availHeight + "<br>";
		text += "availWidth:" + screen.availWidth + "<br>";
		text += "colorDepth:" + screen.colorDepth + "<br>";
		text += "pixelDepth:"	+ screen.pixelDepth + "<br>";
		text += "height:" + screen.height + "<br>";
		text += "width:" + screen.width + "<br>";
	document.getElementById("div").innerHTML = text;
}
</script>
</head>
<body onload="printScreen()">
<h3>์Šคํฌ๋ฆฐ ์žฅ์น˜์— ๊ด€ํ•œ ์ •๋ณด</h3>
<hr>
<div id="div"></div>
</body>
</html>

 

 

ex10-12.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>history ๊ฐ์ฒด ํ™œ์šฉ</title>
</head>
<body>
<h3>history ๊ฐ์ฒด ํ™œ์šฉ</h3>
<hr>
<button onclick="history.back()">back()</button>
<button onclick="history.forward()">forward()</button>
<button onclick="history.go(-1)">go(-1)</button>
</body>
</html>

 

 

๋Œ“๊ธ€