Window focus and blur() : Window « Window Browser « JavaScript DHTML






Window focus and blur()

  


/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

John Wiley & Sons CopyRight 2001
*/

<HTML>
<HEAD>
<TITLE>Window Focus() and Blur()</TITLE>
<SCRIPT LANGUAGE="JavaScript1.1">
// declare global variable name
var newWindow = null
function makeNewWindow() {
    // check if window already exists
    if (!newWindow || newWindow.closed) {
        // store new window object in global variable
        newWindow = window.open("","","width=250,height=250")
        // pause briefly to let IE3 window finish opening
        setTimeout("fillWindow()",100)
    } else {
        // window already exists, so bring it forward
        newWindow.focus()
    }
}
// assemble new content and write to subwindow
function fillWindow() {
    var newContent = "<HTML><HEAD><TITLE>Another Subwindow</TITLE></HEAD>"
    newContent += "<BODY bgColor='salmon'>"
    newContent += "<H1>A Salmon-Colored Subwindow.</H1>"
    newContent += "<FORM><INPUT TYPE='button' VALUE='Bring Main to Front' onClick='self.opener.focus()'>"
    // the following button doesn't work in NN6
    newContent += "<FORM><INPUT TYPE='button' VALUE='Put Me in Back' onClick='self.blur()'>"
    newContent += "</FORM></BODY></HTML>"
    // write HTML to new window document

newWindow.document.write(newContent)
    newWindow.document.close()
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Window focus() and blur() Methods</H1>
<HR>
<FORM>
<INPUT TYPE="button" NAME="newOne" VALUE="Show New Window" onClick="makeNewWindow()">
</FORM>
</BODY>
</HTML>

           
         
    
  








Related examples in the same category

1.Make a new window
2.Communicating with a New Window
3.Using the window.close() Method to Close a Browser Window
4.Popup window animation (fly across screen)
5.Hyper link to close window
6.Close window and open document in new window
7.Open a new link from a button
8.Open a new window and control its appearance
9.Open multiple windows at one click
10.Resize a window
11.Resize a window to a specified size
12.Scroll the window
13.New Window Laboratory
14.Creating an always Raised Window
15.Window Property Picker
16.Window Resize, motion, maximize
17.Creating a New Window
18.Window Resize Methods
19.Opening and Closing Windows
20.Opening a New Window
21. A Main Window Document
22.References to Window Objects
23.Simple Notification: Display Window Info
24.Properties and Methods of the Window Object
25.Capturing Click Events in the Window
26.Contents of a Main Window Document That Generates a Second Window
27.Setting Window Height and Width(Firefox)
28. Checking Before Closing a Window
29.Open a window and center it
30.Maximize Window for different browser
31.Scroll Window
32.Preventing a Page from Scrolling
33.Open a new window setting height, width and position
34.Move a window
35.To hide JavaScript errors from the user
36.Using document.write() on the Current Window
37.Using document.write() on Another Window