IHTMLWindow2

IHTMLWindow2


This interface provides access to the window object which represents an open window in the browser. You use the window object to retrieve information about the state of the window and to gain access to the document in the window, to the events that occur in the window, and to features of the browser that affect the window.

Typically, the browser creates one window object when it opens an HTML document. However, if a document defines one or more frames (that is, contains one or more FRAME or IFRAME tags), the browser creates one window object for the original document and one additional window object for each frame. These additional objects are child windows of the original window and can be affected by actions that occur in the original. For example, closing the original window causes all child windows to close. You can also create new windows (and corresponding window objects) by using methods such as open and showModalDialog.

IHTMLWindow2 Methods
get_frames   put_defaultStatus   get_defaultStatus  
put_status   get_status   setTimeout  
clearTimeout   alert   confirm  
prompt   get_Image   get_location  
get_history   close   put_opener  
get_opener   get_navigator   put_name  
get_name   get_parent   open  
get_self   get_top   get_window  
navigate   put_onfocus   get_onfocus  
put_onblur   get_onblur   put_onload  
get_onload   put_onbeforeunload   get_onbeforeunload  
put_onunload   get_onunload   put_onhelp  
get_onhelp   put_onerror   get_onerror  
put_onresize   get_onresize   put_onscroll  
get_onscroll   get_document   get_event  
get__newEnum   showModalDialog   showHelp  
get_screen   get_Option   focus  
get_closed   blur   scroll  
get_clientInformation   setInterval   clearInterval  
put_offscreenBuffering   get_offscreenBuffering   execScript  
toString   scrollBy   scrollTo  
moveTo   moveBy   resizeTo  
resizeBy   get_external  

IHTMLWindow2::alert

HRESULT alert( 
    BSTR message 
);

Displays an Alert dialog box with a message and an OK button.

message
String specifying the message to display in the dialog box.

The title bar of the Alert dialog box cannot be changed.

See also confirm, prompt

IHTMLWindow2::blur

HRESULT blur( 
    void 
);

Causes the window to lose focus and fires the onblur event.

See also focus

IHTMLWindow2::clearInterval

HRESULT clearInterval(
    long timerID 
);

Cancels a repeated evaluation of an expression that was set with the setInterval method.

timerID
Specifies a time-out identifier returned by a previous call to the setInterval method.

See also setInterval

IHTMLWindow2::clearTimeout

HRESULT clearTimeout( 
    long timerID 
);

Cancels a time-out that was set with the setTimeout method.

timerID
Specifies a time-out identifier returned by a previous call to the setTimeout method.

See also setTimeout

IHTMLWindow2::close

HRESULT close( 
    void 
);

Closes the current browser window.

IHTMLWindow2::confirm

HRESULT confirm(
    BSTR message,
    VARIANT_BOOL *confirmed
);

Displays a Confirm dialog box with the specified message, and OK and Cancel buttons.

message
String specifying the message to display in the dialog box.
confirmed
Address of a variable that receives TRUE if the message is confirmed, or FALSE otherwise.

The title bar of the confirm dialog box cannot be changed.

See also alert, prompt

IHTMLWindow2::execScript

HRESULT execScript(
    BSTR code,
    BSTR language,
    VARIANT *pvarRet
);

Executes the specified script.

code
String specifying the script code to execute.
language
String specifying the language in which the code is executed. The default is JScript.
pvarRet
Address of a variable that receives the return value from the script code.

IHTMLWindow2::focus

HRESULT focus(
    void 
);

Causes the window to receive the input focus and execute the code, if any, associated with the onfocus event.

See also blur

IHTMLWindow2::get__newEnum

HRESULT get__newEnum(
    IUnknown **p 
);

Returns an OLE enumeration interface. This will enumerate over the frames collection of this window.

p
Address of a pointer to an IUnknown interface.

IHTMLWindow2::get_clientInformation

HRESULT get_clientInformation( 
    IOmNavigator **p 
);

Retrieves an interface pointer to a navigator object that represents the browser. The object provides information about the browser.

p
Address of a variable that receives the interface pointer.

See also IOmNavigator

IHTMLWindow2::get_closed

HRESULT get_closed(
    VARIANT_BOOL *p 
);

Retrieves a value indicating whether the window is closed.

p
Address of a variable that receives TRUE if the window is closed, or FALSE otherwise.

IHTMLWindow2::get_defaultStatus

HRESULT get_defaultStatus( 
    BSTR *p 
);

Retrieves the default message displayed in the status bar at the bottom of the window.

p
Address of a variable that receives the default status message.

Do not confuse the defaultStatus property with the status property retrieved by the get_status method. The status property reflects a priority or transient message in the status bar, such as the message that appears when an onmouseover event occurs over an anchor.

See also put_defaultStatus

IHTMLWindow2::get_document

HRESULT get_document( 
    IHTMLDocument2 **p 
);

Retrieves an interface pointer to the document object for the document that the browser is displaying.

p
Address of a variable that receives the interface pointer.

See also IHTMLDocument2

IHTMLWindow2::get_event

HRESULT get_event(
    IHTMLEventObj **p 
);

Retrieves an interface pointer to the event object that contains information relevant to the most recent event.

p
Address of a variable that receives the interface pointer.

See also IHTMLEventObj

IHTMLWindow2::get_external

HRESULT get_external( 
    IDispatch **p 
);

Retrieves external access to an additional object model provided by host applications of the Internet Explorer browser components.

p
Address of a variable that receives the interface pointer.

In the Internet Explorer stand-alone browser, no external object model is available. In a hosting scenario where it is available, the object model is defined by the application hosting the Internet Explorer components, and the hosting application should be referred to for documentation. For further details on how to implement extensions to the object model, see the Internet Client SDK documentation on "Reusing the WebBrowser and MSHTML".

IHTMLWindow2::get_frames

HRESULT get_frames(
    IHTMLFramesCollection2 **p 
);

Retrieves an interface pointer to a zero-based collection of all the FRAME elements in an HTML document, if the document contains the FRAMESET element. If the document contains the BODY element, this is a collection of all IFRAME elements in the document. In either case, the elements are in the same order as they appear in the document.

p
Address of a variable that receives the interface pointer.

The collection is indexed first by name, then by ID. If duplicate names are found, a collection of those named items is returned. The resulting collection can be only referenced by ordinal position.

IHTMLWindow2::get_history

HRESULT get_history( 
    IOmHistory **p 
);

Retrieves an interface pointer to a history object that contains information about all the URLs that the client has visited.

p
Address of a variable that receives the interface pointer.

IHTMLWindow2::get_Image

HRESULT get_Image( 
    IHTMLImageElementFactory **p 
);

Returns an IHTMLImageElementFactory pointer that is used to create an offscreen image.

p
Address of a variable that receives an IHTMLImageElementFactory interface pointer.

IHTMLWindow2::get_location

HRESULT get_location( 
    IHTMLLocation **p 
);

Retrieves an interface pointer to a location object. The object contains information about the current location (full URL) of the document.

p
Address of a variable that receives the interface pointer.

IHTMLWindow2::get_name

HRESULT get_name(
    BSTR *p 
);

Retrieves the name of the window.

p
Address of a variable that receives the name.

The name property on the window comes from the FRAME definition. There is no other way to persist a window name in HTML.

See also put_name

IHTMLWindow2::get_navigator

HRESULT get_navigator( 
    IOmNavigator **p 
);

Retrieves an interface pointer to a navigator object that represents the browser. The object provides information about the browser.

p
Address of a variable that receives the interface pointer.

See also IOmNavigator

IHTMLWindow2::get_offscreenBuffering

HRESULT get_offscreenBuffering(
    VARIANT *p 
);

Determines whether an offscreen buffer is being used.

p
Address of a variable that receives a value indicating if a buffer is being used.

See also put_offscreenBuffering

IHTMLWindow2::get_onbeforeunload

HRESULT get_onbeforeunload( 
    VARIANT *p
);

Retrieves the inline script associated with the onbeforeunload event before a window element is unloaded. This event is fired before the onunload event. It provides an opportunity to warn the user if the window is currently in an unsaved state and the information will be lost.

For more information on inline script, see Attaching an Event Handler in the Event Model documentation.

p
Address of a VARIANT structure that contains the script.

The handler for this event should return NULL if doing the unload is safe, or a text string to prompt the user to decide to cancel or continue with the unload operation. Only the user's response to the warning can stop the new navigation causing the unload; the event handler itself cannot unilaterally block the operation. If the handler returns a non-NULL string, a modal dialog box appears that displays the explanatory string. The dialog box shows three buttons with the message for user action:

In the case of frames, the full sequence of onbeforeunload events are fired on each frame in the same order, depth-first, that onunload events are about to be fired. A dialog box is presented for each event handler that returns a non-NULL string. The first Cancel response stops the potential navigation, in which case no unload occurs. If there is no Cancel response, the unload proceeds and onunload events fire.

See also put_onbeforeunload

IHTMLWindow2::get_onblur

HRESULT get_onblur(
    VARIANT *p 
);

Retrieves the inline script associated with the onblur event when the window element loses the focus.

For more information on inline script, see Attaching an Event Handler in the Event Model documentation.

p
Address of a string variable that contains the script.

See also put_onblur

IHTMLWindow2::get_onerror

HRESULT get_onerror(
    VARIANT *p 
);

Retrieves the inline script associated with the onerror event on the window element.

For more information on inline scripts, see Attaching an Event Handler in the Event Model documentation.

v
Address of a VARIANT structure that contains the onerror script.

See also put_onerror

IHTMLWindow2::get_onfocus

HRESULT get_onfocus(
    VARIANT *p 
);

Retrieves the inline script associated with the onfocus event on the window element.

For more information on inline scripts, see Attaching an Event Handler in the Event Model documentation.

p
Address of a VARIANT structure that contains the onfocus script.

See also put_onfocus

IHTMLWindow2::get_onhelp

HRESULT get_onhelp(
    VARIANT *p 
);

Retrieves the inline script associated with the onhelp event on the window element.

For more information on inline scripts, see Attaching an Event Handler in the Event Model documentation.

p
Address of a VARIANT structure that contains the onhelp script.

This script is executed when the user presses the F1 key or clicks the Help button in the browser. The default action of this event is to display the help information for the browser.

See also put_onhelp

IHTMLWindow2::get_onload

HRESULT get_onload( 
    VARIANT *p 
);

Retrieves the inline script that is executed immediately after the browser loads the given object.

p
Address of a VARIANT structure that contains the script.

See also put_onload

IHTMLWindow2::get_onresize

HRESULT get_onresize( 
    VARIANT *p 
);

Retrieves the inline script that is executed when the object is resized.

p
Address of a VARIANT structure that contains the script.

See also put_onresize

IHTMLWindow2::get_onscroll

HRESULT get_onscroll(
    VARIANT *p 
);

Retrieves the inline script that is executed when the scroll box is repositioned. The default action of this event is to scroll.

p
Address of a VARIANT structure that contains the script.

See also put_onscroll

IHTMLWindow2::get_onunload

HRESULT get_onunload(
    VARIANT *p 
);

Retrieves the inline script that is executed immediately before the page is unloaded.

p
Address of a VARIANT structure that contains the script.

See also put_onunload

IHTMLWindow2::get_opener

HRESULT get_opener( 
    VARIANT *p 
);

Retrieves a reference to the window that created the current window.

p
Address of a variable that receives the reference to the creating window.

See also put_opener

IHTMLWindow2::get_Option

HRESULT get_Option(
    IHTMLOptionElementFactory **p 
);

Retrieves an interface pointer to a factory object that you can use to create OPTION elements. You can add the elements to a SELECT block by using the IHTMLSelectElement::add method.

p
Address of a variable that receives the interface pointer.

See also IHTMLOptionElementFactory, IHTMLSelectElement::add

IHTMLWindow2::get_parent

HRESULT get_parent(
    IHTMLWindow2 **p
);

Retrieves an interface pointer to the parent object in the object hierarchy.

p
Address of a variable the receives the interface pointer.

In a FRAMESET and FRAME relationship, this function retrieves an object representing the FRAMESET window. On a document, the parent is the window.

IHTMLWindow2::get_screen

HRESULT get_screen( 
    IHTMLScreen **p 
);

Retrieves an interface pointer to a screen object that provides information about the client's screen and rendering abilities

p
Address of a variable that receives the interface pointer.

See also IHTMLScreen

IHTMLWindow2::get_self

HRESULT get_self( 
    IHTMLWindow2 **p
);

Retrieves an interface pointer to the current window.

p
Address of a variable that receives the interface pointer.

Use the self property to disambiguate a window property from a form of the same name.

IHTMLWindow2::get_status

HRESULT get_status(
    BSTR *p
);

Retrieves the message displayed in the status bar at the bottom of the window.

p
Address of a variable that receives the status message.

Do not confuse the status property with the defaultStatus property retrieved by the get_defaultStatus method. The status property reflects a priority or transient message in the status bar, such as the message that appears when an onmouseover event occurs over an anchor.

See also put_status

IHTMLWindow2::get_top

HRESULT get_top( 
    IHTMLWindow2 **p 
);

Retrieves an interface pointer to the topmost ancestor window, which is the current window's own parent.

p
Address of a variable that receives the interface pointer.

IHTMLWindow2::get_window

HRESULT get_window(
    IHTMLWindow2 **p 
);

Retrieves an interface pointer to the current window.

p
Address of a variable that receives the interface pointer.

Use the self property to disambiguate a window property from a form of the same name.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.