본문 바로가기

   
Programming/Javascript

Javascript window 함수

반응형
소스
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

       <head>

             <title></title>

             <meta name="generator" content="editplus" />

             <meta name="author" content="김종현" />

             <script type="text/javascript">

                    function Test1()

                    {

 

                           //현재 창의 크기를 변경(pixel)

                           //window.resizeTo(10, 10);//절대값

                           window.resizeBy(-10, -10); //상대값

                    }

 

 

                    function Test2()

                    {

                           //window.moveTo(-100, -100);//절대값

                           window.moveBy(0, -10);

                    }

 

                    function Test3()

                    {

                           setInterval("Test1();", "100");

                    }

 

                    function Test4()

                    {

                           //window는 최상위이며 유일하기 때문에 윈도우를 생략하고 사용한다.

                           location.href = "http://www.naver.com";

                    }

             </script>

       </head>

 

       <body>

             <!-- Ex07.htm -->

             <input type="button" value="창의 크기를 변경" onclick="Test1();" />

             <hr />

 

             <input type="button" value="창의 위치를 변경" onclick="Test2();" />

             <hr />

 

             <input type="button" value="창의 위치를 변경" onclick="Test3();" />

             <hr />

 

             <input type="button" value="창의 소스(url)를 변경" onclick="Test4();" />

       </body>

</html>

 

결과

익스플로러에서 테스트 하면 인터넷 창이 전체적으로 움직이는것을 확인할수 있다.


소스

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>Window</title>

 

       <script type="text/javascript">

 

             function Test1()

             {

                    //대화상자(MessageBox.Show())

                    //window.alert("메시지");

 

                    //var result = window.confirm("메시지");

                    //alert(result);//true, false

 

                    //var result = window.prompt("메시지", "초기값");

                    //alert(result);

             }

 

             function Test2()

             {

                    //창에 관련된 멤버

                    //window.moveTo(0, 0);

                    //window.moveBy(10, 10);

 

                    //window.resizeTo(200, 200);

                    //window.resizeBy(10, 10);

             }

 

             function Test3()

             {

                    //형변환(string(int,float) -> int, float)

                    //var num = window.prompt("숫자를 입력하시오", "");

 

                    //alert(num + 100);

                    //alert(parseInt(num) + 100);

 

 

                    //parse() : 앞에서 나오는 숫자만 취함!!

                    //var num = "100입니다.";

                    //alert(parseInt(num) * 2);

 

                    //var num2 = "3.14라네요~";

                    //alert(parseFloat(num2) * 20);

 

                    //CSS제어

                    // 주로 반환값이 수치일 경우.. "100px" 반환

                    //alert("100px" + 100);

                    //alert(parseInt("100px") + 100);//*****

 

                    //alert(parseInt(3.14));

 

 

                    //Is not a Number?

                    // - 유효성 검사 -> 숫자만 입력받을 때..

                    //alert(!window.isNaN("스무살"));

 

 

                    //var result = window.eval("10 + 20");

                    //alert(result);

 

                    //첫번째 버튼

                    //var i = 1;

                    //var btn1 = document.all.btn + i;

                    //btn1.value = "찾음!!";

 

                    var btn1 = eval("document.all.btn" + "1");

                    btn1.value = "하하하";

             }

 

             function Test4()

             {

                    //타이머 작업 x2종류

                    //window.setTimeout() - 1회용(재귀호출 -> 반복용)

                    //window.setInterval() - 반복용

                    //document.title = "제목";

 

                    //window.setTimeout("ShowTime();", 1000);

                    result = window.setInterval("ShowTime2();", 1000);

             }

 

             function ShowTime2()

             {

                    document.title = new Date().toLocaleTimeString();

             }

 

             function ShowTime()

             {

                    document.title = new Date().toLocaleTimeString();

                    //Timer ID를 반환

                    result = window.setTimeout("ShowTime();", 1000); //재귀

                    //alert(result);

             }

 

             var result;

 

             function ClearTime()

             {

                    //result를 접근

                    //window.clearTimeout(result);

                    window.clearInterval(result);

             }

       </script>

</head>

<body>

       <!--Ex10_window.htm-->

       <input type="button" value=" 테스트1 " onclick="Test1();" name="btn1" /><br />

       <input type="button" value=" 테스트2 " onclick="Test2();" /><br />

       <input type="button" value=" 테스트3 " onclick="Test3();" /><br />

       <input type="button" value=" 테스트4 " onclick="Test4();" /><br />

       <input type="button" value=" 테스트5 " onclick="ClearTime();" /><br />

</body>

</html>

결과 





반응형