Press "Enter" to skip to content

Window Examples in JavaScript

Definition :

It is an object of java script which is meant for performing the operations on the browser window.

Program 1 :

<html>

     <head>

                     <script language=”javascript”>

                                     function display()

                                                 {

                                                     window.location=”Desert.jpg”;

                                                  }

                                </script>

                </head>

                <body>

                     <input type=”button” value=”show” onclick=”display()”/> </br>

                </body>

</html>

Program 2:

<html>

     <head>

                     <script language=”javascript”>

                                     function display()

                                                 {

                                                     window.location.replace(“Desert.jpg”);

                                                  }

                                </script>

                </head>

                <body>

                     <input type=”button” value=”show” onclick=”display()”/> </br>

                </body>

</html>

Window dimensions :

 Program 3 :

<html>

     <head>

                     <script language=”javascript”>

                                     function display()

                                                 {

                                                    document.write(window.innerHeight+”</br>”);

                                                                document.write(window.innerWidth+”</br>”);

                                                  }

                                </script>

                </head>

                <body>

                     <input type=”button” value=”getdata” onclick=”display()”/> </br>

                </body>

</html>

Window open :

Program 4 :

<html>

     <head>

                     <script language=”javascript”>

                                     function display()

                                                 {

                                                   window.open(“Desert.jpg”);

                                                  }

                                </script>

                </head>

                <body>

                     <input type=”button” value=”open” onclick=”display()”/> </br>

                </body>

</html>

Program 5 :

<html>

     <head>

                     <script language=”javascript”>

                                     function display()

                                                 {

                                                   window.open(“Desert.jpg”,”_blank”,”title”,”width=100, height=100″);

                                                  }

                                </script>

                </head>

                <body>

                     <input type=”button” value=”open” onclick=”display()”/> </br>

                </body>

</html>

Program 6 :

<html>

    <head> <script language=”javascript”>

                function display()

                {

    a=window.open(“”,”_blank”,”title”,”width=100,height=100″);

                a=document.write(“<h1> <center>HELLO</center> </h1>”);

                }

                </script> </head>

                <body>

                  <input type=”button” value=”open” onClick=”display()”/> </br>

                </body>

</html>

Program 7 :

<html>

    <head> <script language=”javascript”>

                function display()

                {

    a=window.open(“Desert.jpg “);

                a.document.write(“<h1> <center>HELLO</center> </h1>”);

                }

                function closeme()

                {

                a=window.close(“Desert.jpg”);

                }

                </script> </head>

                <body>

                  <input type=”button” value=”open” onClick=”display()”/> </br>

                  <input type=”button” value=”close” onclick=”closeme()”/> </br>

                </body>

</html>

Window print :

This is a function which enables the website to go for printing

Program 8 :

<html>

    <head> <script language=”javascript”>

                function display()

                {

    window.print();

                }

                </script> </head>

                <body>

                   <h1> HELLO WELCOME </h1>

                  <input type=”button” value=”print me” onClick=”display()”/> </br>

                </body>

</html>

Program 9 :

<html>

    <head> <script language=”javascript”>

                function display()

                {

                a=document.getElementById(“demo”).innerHTML;

                document.write(a);

                window.print();

                }

                </script> </head>

                <body>

                <div id=”demo”> <h1>HELLO WELCOME</h1> </div>

                  <input type=”button” value=”print me” onClick=”display()”/> </br>

                </body>

</html>

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *