• home
  • forum
  • my
  • kt
  • download
  • JavaScript Window Object explanation

    Author: 2007-08-08 09:53:12 From:

    Events
    EventsDescription
    onblurCode is executed when the window loses focus.
    onerrorCode is executed when a JavaScript error occurs.
    onfocusCode is executed when the focus is set on the current window.
    onloadCode is executed when the page has finished loading.
    onresizeCode is executed when the window is resized.
    onunloadCode is executed when the page is unloaded (visitor leaves the page).

    *Most of the events above can be defined in two ways. Using "onload" as an example:

    <body onload="dothis()">
    window.onload=dothis //inside your script

    Properties

    PropertiesDescription
    closedReturns the Boolean variable indicating whether window has been closed or not.
    defaultStatusRead/write property that reflects the default window status bar message that appears.
    documentReference to the current document object.
    framesAn array referencing all of the frames in the current window. Use frames.length to probe the number of frames.
    historyReference to the History object of JavaScript, which contains information on the URLs the visitor has visited within the window.
    lengthReturns the number of frames contained in the window.
    locationReference to the Location object of JavaScript, which contains information on the current URL.
    nameThe name of the window as optionally specified when calling window.open().
    openerContains a reference to the window that opened the secondary window via window.open(). This property should be invoked in the secondary window.
    parentReference to the parent window of the current window, assuming current window is a frame. Otherwise, it simply refers to current window.
    selfA synonym for the current window.
    statusA read/write property that allows you to probe and write to the browser's status bar.
    topA synonym for the topmost browser window.
    windowReferences the current window. Same as "self."
    innerWidth, innerHeightSpecifies the width and height, in pixels, of the window's content area respectively. Read/Write. Does not include the toolbar, scrollbars etc. NS4 and NS6+ only.
    Note: IE4+ equivalents are "document.body.clientWidth" and "document.body.clientHeight"
    outerWidth, outerHeightSpecifies the total width and height, in pixels, of the window's content area respectively. Read/Write. Includes any toolbar, scrollbars etc. NS4 and NS6+ only.
    pageXOffset, pageYOffsetReturns an integer representing the pixels the current document has been scrolled from the upper left corner of the window, horizontally and vertically, respectively. NS4 and NS6+ only.

    Note: IE4+ equivalents are "document.body.scrollLeft" and "document.body.scrollTop"

    screenX, screenYSpecifies the x and y coordinates of the window relative to the user's monitor screen. NS4 and NS6+ only.
    screenLeft, screenTopSpecifies the x and y coordinates of the window relative to the user's monitor screen. IE5+ only.

    Methods

    Note: "[]" surrounding a parameter below means the parameter is optional.

    MethodsDescription
    alert(msg)Displays an Alert dialog box with the desired message and OK button.
    blur()Removes focus from the window in question, sending the window to the background on the user's desktop.
    clearInterval(ID)Clears the timer set using ID=setInterval().
    clearTimeout(ID)Clears the timer set using ID=setTimeout().
    close()Closes a window.
    confirm(msg)Displays a Confirm dialog box with the specified message and OK and Cancel buttons. Example(s)
    find(string, [casesensitive], [backward])Searches for the "string" within the page, and returns string or false, accordingly. "casesensitive" is a Boolean denoting whether search is case sensitive. "backwards" is a Boolean when set to true, searches the page backwards. Final two optional parameters must be set together or none at all. NS4/NS6+ exclusive method.
    focus()Sets focus to the window, bringing it to the forefront on the desktop.
    home()Navigates the window to the homepage as designated by the user's browser setting. NS4/NS6+ only.
    moveBy(dx, dy)Moves a window by the specified amount in pixels.
    moveTo(x, y)Moves a window to the specified coordinate values, in pixels.
    open(URL, [name], [features], [replace])Opens a new browser window. "Name" argument specifies a name that you can use in the target attribute of your <a> tag. "Features" allows you to show/hide various aspects of the window interface. "Replace" is a Boolean argument that denotes whether the URL loaded into the new window should add to the window's history list. A value of true causes URL to not be added. Example(s)
    print()Prints the contents of the window or frame.
    prompt(msg, [input])Displays a Prompt dialog box with a message. Optional "input" argument allows you to specify the default input (response) that gets entered into the dialog box. Set "input" to "" to create a blank input field. Example(s)
    resizeBy(dx, dy)Resizes a window by the specified amount in pixels.
    resizeTo(x y)Resizes a window to the specified pixel values.
    scrollBy(dx, dy)Scrolls a window by the specified amount in pixels.
    scrollTo(x, y)Scrolls a window to the specified pixel values.
    setInterval("func", interval, [args])Calls the specified "func" (or a JavaScript statement) repeatedly per the "interval" interval, in milliseconds (ie: 1000=every 1 second). "func" must be surrounded in quotations, as if it was a string. Use the optional "args" to pass any number of arguments to the function.
    setTimeout("func", interval)Calls the specified "func" (or a JavaScript statement) once after "interval" has elapsed, in milliseconds (ie: 1000=after 1 second). "func" must be surrounded in quotations, as if it was a string.
    stop()Stops the window from loading. NS4/NS6+ exclusive method.

    Window Features in window.open()

    The below lists the string features you can pass into the "feature" parameter of window.open() to manipulate its interface. Most features support a value of true or false, though in general, simply including the name of the feature implies it should be added to the window (yes), while not including it means it shouldn't (no). Separate each feature with a comma (,).

    FeatureDescription
    channelmodeSpecifies if window should be opened in channel mode. IE only.
    fullscreenSpecifies if window should be opened in full screen mode. IE only.
    heightSpecifies the height of the window.
    leftSpecifies the x coordinates of the window in pixels. IE only. See "screenX" as well.
    locationSpecifies if the location bar of the window should be included.
    menubarSpecifies if the menu bar of the window should be included.
    resizableSpecifies if window should be resizable.
    screenXSpecifies the x coordinates of the window in pixels. NS only. See "left" as well.
    screenYSpecifies the x coordinates of the window in pixels. NS only. See "top" as well.
    scrollbarsSpecifies if window should contain scrollbars.
    statusSpecifies if the status bar of the window should be included.
    toolbarSpecifies if the toolbar of the window (ie: reload button) should be included.
    topSpecifies the y coordinates of the window in pixels. IE only. See "screenY" as well.
    widthSpecifies the width of the window.

    Examples

    open(URL, [name], [features], [replace])

    window.open("http://www.dynamicdrive.com", "", "width=800px, height=600px, resizable")

    confirm(msg)

    var yourstate=window.confirm("Are you sure you are ok?")
    if (yourstate) //Boolean variable. Sets to true if user pressed "OK" versus "Cancel."
    window.alert("Good!")

    prompt(msg, [input])

    var thename=window.prompt("please enter your name")
    window.alert(thename)

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      AJAX (20)
      Content Management (7)
      Cookies (4)
      Date and Time (12)
      Development (7)
      DHTML (14)
      Forms (8)
      Frequently Asked Questions (1)
      Image Display (9)
      Introduction to Javascript (5)
      Links and Buttons (4)
      Menus (2)
      Miscellaneous (5)
      Mouse Tricks (3)
      Navigation (8)
      Randomizing (4)
      Security (1)
      Text Effects (6)
      User Authentication (2)
      User Information (5)
      Windows and Frames (3)

    New

    Hot