[ex18~22] screen, location, history, collection, link
ex18
screen ๊ฐ์ฒด
- window ๊ฐ์ฒด์ ์์
- ํ๋ฉด ์ ๋ณด ์ ๊ณต
//ํ์ฌ ๋ณด๊ณ ์๋ ํ๋ฉด์ ํฌ๊ธฐ > ๋ชจ๋ํฐ ํด์๋ (๋ฐฐ์จ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ๋์ด)
console.log(window.screen.availWidth); //1536
console.log(window.screen.availHeight); //824
console.log(window.screen.colorDepth); //24bit color
console.log(window.screen.orientation); //ScreenOrientation {anger: 0, type: 'landscape-primary', onchange: null}
ex19
location ๊ฐ์ฒด
- window์ ์์
- ํ์ฌ ์ฐฝ์ ํ์ด์ง(URL)์ ๊ด๋ จ๋ ์กฐ์
<body>
<!-- ex19_location.html -->
<form name="form1">
<input type="button" name="btn1" value="ํ์ธ">
</form>
<script>
window.document.form1.btn1.onclick = m1;
function m1() {
//href > reference a hyperlink
// console.log(window.location.href);
//JavaScript + ํ์ด์ง ์ด๋
// window.location.href = 'https://naver.com';
// console.log(window.location.host); //127.0.0.1:5500
// console.log(window.location.hostname); //127.0.0.1
// console.log(window.location.protocol); //http:
// console.log(window.location.port); //5500
//window.location.reload(); //์๋ก ๊ณ ์นจ(F5)
// window.location.href = 'ex19_location.html'; //์๋ก ๊ณ ์นจ
// window.location.replace('https://naver.com');
window.location.href = 'https://naver.com';
//window.location.href > ***์ ์ผ ๋ง์ด ์
//window.location.reload()
//window.location.replace()
}
</script>
</body>
</html>
ex20
history ๊ฐ์ฒด
- window์ ์์
- ๋ธ๋ผ์ฐ์ ์ ํ์ ๊ธฐ๋ก(history) ์์ญ ์ ๊ทผํ๋ ๊ฐ์ฒด
<body>
<!-- ex20_history.html -->
<form name="form1">
<input type="button" name="btn1" value="๋ค๋ก ๊ฐ๊ธฐ">
<input type="button" name="btn2" value="์์ผ๋ก ๊ฐ๊ธฐ">
<input type="button" name="btn3" value="2๋จ๊ณ ๋ค๋ก ๊ฐ๊ธฐ">
<input type="button" name="btn4" value="2๋จ๊ณ ์์ผ๋ก ๊ฐ๊ธฐ">
</form>
<script>
//history ๊ฐ์ฒด
//- window์ ์์
//- ๋ธ๋ผ์ฐ์ ์ ํ์ ๊ธฐ๋ก(history) ์์ญ ์ ๊ทผํ๋ ๊ฐ์ฒด
// window.document.form1.btn1 > window(๋ง) ์๋ต ๊ฐ๋ฅ
document.form1.btn1.onclick = m1;
document.form1.btn2.onclick = m2;
document.form1.btn3.onclick = m3;
document.form1.btn4.onclick = m4;
//ex20 > ๋ค์ด๋ฒ > ๋ค์ > ex20 > ๊ตฌ๊ธ > yes24
function m1() {
window.history.back(); //๋ค๋ก ๊ฐ๊ธฐ
}
function m2() {
history.forward(); //์์ผ๋ก ๊ฐ๊ธฐ
}
function m3() {
history.go(-2);
}
function m4() {
history.go(2);
}
</script>
</body>
ex21
๋ด์ฅ ๋ฐฐ์ด(์ปฌ๋ ์
), collection
- ๋ฌธ์ ์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์๋ ์์ฑ๋๋ ๋ฐฐ์ด์ ์ ๊ณตํ๋ค.
1. window.document.images > ๋ฌธ์๋ด์ ๋ชจ๋ <img> ํ๊ทธ
2. window.document.links > ๋ฌธ์๋ด์ ๋ชจ๋ <a href=""> ํ๊ทธ
3. window.document.anchors > ๋ฌธ์๋ด์ ๋ชจ๋ <a name=""> ํ๊ทธ
4. window.document.forms > ๋ฌธ์๋ด์ ๋ชจ๋ <form> ํ๊ทธ
5. window.document.forms[index].elements > ํน์ ํผํ๊ทธ ๋ด์ ๋ชจ๋ ์
๋ ฅํ๊ทธ
6. window.document.forms[index].select.option > <option> ํ๊ทธ
7. window.document.all > ๋ฌธ์์์ ๋ชจ๋ ํ๊ทธ(๋นํ์ค MS)
<body>
<!-- ex21_collection.html -->
<h1>์ด๋ฏธ์ง</h1>
<img src="images/catty01.png">
<img src="images/catty02.png">
<img src="images/catty03.png" name="cat3">
<img src="images/catty04.png">
<img src="images/catty05.png">
<h1>๋งํฌ+์ต์ปค</h1>
<a href="#1" name="link1">๋งํฌ1</a>
<a href="#2">๋งํฌ2</a>
<a href="#3">๋งํฌ3</a>
<a name="a1">์ต์ปค1</a>
<a name="a2">์ต์ปค2</a>
<h1>ํผ</h1>
<form name="form1">
<input type="text" name="txt1">
<input type="text" name="txt2">
<input type="text" name="txt3">
</form>
<form>
</form>
<script>
// console.log(document.images.length);
// for (var i=0; i<5; i++) {
// console.log(document.images[i].src);
// //http://127.0.0.1:5500/javascript/images/catty01.png
// }
// document.images[0].width = 300;
// document.images['cat3'].width = 300;
// console.log(document.links.length);
// console.log(document.links[0].href);
// console.log(document.links['link1'].href);
// console.log(document.anchors.length);
// console.log(document.anchors[0].name);
// console.log(document.anchors['a1'].name);
// document.form1
// document.forms[0]
// console.log(document.forms.length);
//form1ํ๊ทธ์ ์์ํ๊ทธ
// console.log(document.form1.elements.length);
// document.form1.txt1.value = "ํ๊ธธ๋";
// document.form1.elements[1].value = '์๋ฌด๊ฐ';
//all > ๋ฌธ์์์ ๋ชจ๋ <form> + ์
๋ ฅ ํ๊ทธ + ์ด๋ฏธ์ง + ๋งํฌ
//all > ๋ฌธ์์์ ๋ชจ๋ ํ๊ทธ
console.log(document.all.length); //26
</script>
</body>
</html>
ex22
Link
<body>
<!-- ex22_link.html -->
<h1>๋งํฌ</h1>
<a href="https://naver.com" name="link1">๋ค์ด๋ฒ</a>
<hr>
<button type="button" name="btn1">ํ์ธ</button>
<script>
document.all.btn1.onclick = m1;
function m1() {
// link1์ ์์ฑ๊ฐ์ ๋ค์ด๋ฒ > ๊ตฌ๊ธ๋ก ์กฐ์
document.links['link1'].href = 'http://google.com';
// ์์ฐฝ์์ ์ด๋ฆผ
document.links['link1'].target = '_blank';
document.links['link1'].title = '๊ตฌ๊ธ๋ก ์ด๋ํฉ๋๋ค';
//DOM
// document.links['link1'].innerText = '๊ตฌ๊ธ'; //๋นํ์ค(MS)
document.links['link1'].textContent = '๊ตฌ๊ธ'; //ํ์ค
}
</script>
</body>
</html>