iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning JavaScript Course: Window - www.itechcollege.com JavaScript Course: Window - www.itechcollege.com
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

courses > JavaScript > Window

Window

Open a window To open a window, simply use the method "window.open()":

     <form>
     <input type="button" value="Click here to see" 
                        onclick="window.open('test.htm')">
     </form> 

You can replace "test.htm" with any URL, for example, with "http://www.yahoo.com".

Size, toolbar, menubar, scrollbars, location, status Let's add some of attributes to the above script to control the size of the window, and show: toolbar, scrollbars etc. The syntax to add attributes is:

     open("URL","name","attributes")

For example:

     <form>
     <input type="button" value="Click here to see" 
     onclick="window.open('p2.htm','w1','width=200,height=200,menubar')">
     </form> 

Another example with no attributes turned on, except the size changed:

     <form>
     <input type="button" value="Click here to see" 
     onclick="window.open('p2.htm','w1','width=200,height=200')">
     </form>

Here are the complete list of attributes you can add:

width height toolbar
location directories status
scrollbars resizable menubar

Reload To reload a window, use this method:

     window.location.reload()

Close Window Your can use one of the below codes:

     <form>
     <input type="button" value="Close Window" 
                        onClick="window.close()">
     </form>
     <a href="javascript:window.close()">Close Window</a>

LoadingThe basic syntax when loading new content into a window is:

     window.location="test.htm"

This is the same as

     <a href="test.htm>Try this </a>

Let's provide an example, where a confirm box will allow users to choose between going to two places:

     <script>
     <!--
     function ss()
     {
     var ok=confirm('Click "OK" to itechcollege, 
			"CANCEL" to onlineschoolnet');
     if (ok)
     location="http://www.itechcollege.com";
     else
     location="http://www.onlineschoolnet.com";
     }
     //-->
     </script>

Remote Contral Window Let's say you have opened a new window from the current window. After that, you will wonder how to make a control between the two windows. To do this, we need to first give a name to the window.Look at below:

     aa=window.open('test.htm','','width=200,height=200')

By giving this window a name "aa", it will give you access to anything that's inside this window from other windows. Whenever we want to access anything that's inside this newly opened window, for example, to write to this window, we would do this: aa.document.write("This is a test.").

Now, let's see an example of how to change the background color of another window:

     <html><head><title></title></head>
     <body>
     <form>
     <input type="button" value="Open another page" 
     onClick="aa=window.open('test.htm','','width=200,height=200')">
     <input type="radio" name="x" 
               onClick="aa.document.bgColor='red'">
     <input type="radio" name="x" 
               onClick="aa.document.bgColor='green'">
     <input type="radio" name="x" 
               onClick="aa.document.bgColor='yellow'"> 
     </form>
     </body></html>

opener Using "opener" property, we can access the main window from the newly opened window.

Let's create Main page:

     <html>
     <head>
     <title></title>
     </head>
     <body>
     <form>
     <input type="button" value="Open another page" 
     onClick="aa=window.open('t1.htm','','width=100,height=200')">
     </form>
     </body>
     </html>

Then create Remote control page (in this example, that is "t1.htm"):

     <html>
     <head>
     <title></title>
     <script>
     function remote(url){
     window.opener.location=url
     }
     </script>
     </head>
     <body>
     <p><a href="#" onClick="remote('file1.htm')">File 
     1</a></p>
     <p><a href="#" onClick="remote('file2.htm')">File 
     2</a></p>
     </body>
     </html>

Try it now!



  Back to Index Page
 Next Page:  

Embedding and including
write and writeln
Document object
Message box
Variables and Conditions
Function
Event handler
Form
Link
Date
Window
Frame


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech