www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Methods
 open Method
open Method

Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the sUrl parameter and the sName parameter to collect the output of the write method and the writeln method.

Syntax

oNewDoc = document.open(sUrl [, sName] [, sFeatures] [, bReplace])

Parameters

sUrl Required. When a new document is opened, sUrl is a String that specifies a MIME type for the document. When a new window is opened, sUrl is a String that specifies the URL to render in the new window. If a sUrl is not specified, a new window with about:blank is displayed.
text/htmlDefault. Currently the only MIME type supported for this method.
sName Optional. When a new document is opened, specify the String replace for sName to specify that the new document replaces the current document in the history list. If the replace value is not specified when you open a document, a new entry is added to the history list. When a window is opened, this is a String that specifies the name of the window. The value of this parameter can be specified as the value of the TARGET attribute for a form or an a element. This value defines this new window as the location to load a document.
replace This value is only used to open a new document, and specifies that the new document replaces the current entry in the history list.
_blankWhen a window is opened, the sUrl is loaded into a new, unnamed window.
_parentWhen a new window is opened, the sUrl is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self.
_searchDisabled in Windows Internet Explorer 7, see Security and Compatibility in Internet Explorer 7 for details. Otherwise, when a window is opened, the sUrl is opened in the browser's search pane in Microsoft Internet Explorer 5 or later.
_selfWhen a window id opened, the current document is replaced with the specified sUrl .
_topsUrl replaces any framesets that are loaded. If there are no framesets defined, this value acts as the _self value.
_mediaThe sUrl is loaded in the Media Bar in Internet Explorer 6. Microsoft Windows XP Service Pack 2 (SP2) and later. This feature is no longer supported. By default the sUrl is loaded into a new browser window or tab.
sFeatures Optional. This String parameter is a list of comma-separated items. Each item consists of an option and a value, separated by an equals sign (=), for example, "fullscreen=yes, toolbar=yes". The following features are supported.
channelmode = { yes | no | 1 | 0 }Specifies whether to display the window in theater mode. The default is no.

Internet Explorer 7. channelmode = { yes | 1 } overrides the height value, the width value, the top value, and the left value. When active, the Navigation Bar is hidden, and the Title Bar is visible. The Channel Band is no longer supported in Internet Explorer 7.

Prior to Internet Explorer 7 channelmode = { yes | 1 } displays the Channel Band in theatre mode.

directories = { yes | no | 1 | 0 }Specifies whether to add directory buttons. The default is yes.

Internet Explorer 7. This feature is no longer supported.

fullscreen = { yes | no | 1 | 0 }Specifies whether to display the browser in full-screen mode. The default is no. Use full-screen mode carefully. Because this mode hides the browser's title bar and menus, you should always provide a button or other visual clue to help the user close the window. ALT+F4 closes the new window.

Internet Explorer 7. A window in full-screen mode does not have to be in theatre mode.

Prior to Internet Explorer 7, a window in full-screen mode must in theater mode (channelmode).

height = numberInternet Explorer 7. Sets the height of the window in pixels. The minimum value is 150, and specifies the minimum height of the browser content area.

Prior to Internet Explorer 7, the minimum height value is 100.

left = numberSpecifies the left position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to zero.
location = { yes | no | 1 | 0 }Internet Explorer 7. Specifies whether to display the navigation bar. The default is yes.

Prior to Internet Explorer 7, this feature specifies whether to display the address bar.

The Back command, the Forward command, and the Stop command are now located in the Navigation bar. Prior to Internet Explorer 7, navigation commands were located in the toolbar.

menubar = { yes | no | 1 | 0 } Specifies whether to display the menu bar. The default is yes.

Internet Explorer 7. By default the menu bar is hidden, unless it is revealed by the ALT key. menubar = { no | 0 } prohibits the menubar from appearing even when the ALT key is pressed.

The combination of menubar = { no | 0 } and toolbar = { no | 0 } hides the toolbar and disables any additional third-party user interfaces.

resizable = { yes | no | 1 | 0 }Specifies whether to display resize handles at the corners of the window. The default is yes.

Internet Explorer 7. resizable = { no | 0 } disables tabs in a new window.

scrollbars = { yes | no | 1 | 0 }Specifies whether to display horizontal and vertical scroll bars. The default is yes.
status = { yes | no | 1 | 0 }Specifies whether to add a Status Bar at the bottom of the window. The default is yes.
titlebar = { yes | no | 1 | 0 }Specifies whether to display a Title Bar for the window. The default is yes.

Internet Explorer 5.5 and later. This feature is no longer supported. The Title Bar remains visible unless the fullscreen sFeature is active.

This parameter is ignored prior to Internet Explorer 5.5. It applies only if the calling application is an HTML Application or a trusted dialog box.

toolbar = { yes | no | 1 | 0 }Internet Explorer 7. Specifies whether to display the browser command bar, making buttons such as Favorites Center, Add to Favorites, and Tools available. The default is yes.

The combination of menubar = { no | 0 } and toolbar = { no | 0 } turns off the Toolbar and any additional third-party user interfaces.

Prior to Internet Explorer 7, the toolbar sFeature specifies whether to display the browser toolbar, making buttons such as Back, Forward, and Stop available.

top = numberSpecifies the top position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to zero.
width = numberInternet Explorer 7. Sets the width of the window in pixels. The minimum value is 250, and specifies the minimum width of the browser content area.

Prior to Internet Explorer 7, the minimum height value is 100.

bReplace Optional. When the sUrl is loaded into the same window, this Boolean parameter specifies whether the sUrl creates a new entry or replaces the current entry in the window's history list.
truesUrl replaces the current document in the history list
falsesUrl creates a new entry in the history list.

Return Value

Returns a reference to the new document object or the window object. Use this reference to access properties and methods of the new document or window.

Remarks

When a function fired by an event on any object calls the open method, the window. The open method is implied.

<script language="JScript">
function myOpen() {
    open('about:blank');}
</script>
<body >
Click this page and window.open() is called.
</body>

When an event on any object calls the open method, the document.open method is implied.

<button >
Click this button and document.open() is called.
</button>

As of Internet Explorer 6, the _media value of the sName parameter specifies that this method loads a URL in the Media Bar.

Example

The following example shows how to use the open method to replace the current document with a new document and display the HTML markup contained in the variable sMarkup.

<html>
<head>
<title>First Document</title>
<script>
function replace(){
    var "text/html", "replace");
    var sMarkup = "<html><head><title>New Document</title></head><body>Hello, world</body></html>";
    oNewDoc.write(sMarkup);
    oNewDoc.close();
}
</script>
</head>
<body>
<h1>I just want to say</h1><br>
<!--Button will call the replace function and replace the current page with a new one-->
<input type ="button" value = "Finish Sentence" >
</body>
</html>

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 World Wide Web link.

Applies To

document

See Also

close, onbeforeunload
Tags What's this?: Add a tag
Community Content
 
Add Community Content
open a new window without toolbars, menubars      ameade   |   Edit   |  

You can use .open method to open a window without toolbars, menubars, etc. To do this:

<script language="javascript" type="text/javascript">
function open_it(){

//this opens a new window without toolbars, menubars, etc.
lovechild = window.open(file_you_want_to_open.html", "lovechild","height=400,width=200,resizable=0,menubar=0,toolbar=0,location=0,directories=0,scrollbars=0,status=0")


//this sets the opener of the first opened window to the new window you just opened

this.opener=lovechild

//this pauses, then closes the window you first opened
setTimeout("self.close();",5000)
}
</script>


</head>

<body >
</body>

Tags What's this?: dhtml (x) Add a tag
Restriction on sName      A Covington   |   Edit   |  

sName cannot have whitespace in it. I haven't checked, but probably it is restricted to being an identifier. This differs from Firefox's implementation that permits spaces.

Tags What's this?: dhtml (x) Add a tag
Problem with "replace"      ak_47_1982   |   Edit   |  

Using the example given in this reference.....

<html>
<head>
<title>First Document</title>
<script>
function replace(){
var "text/html", "replace");
var sMarkup = "<html><head><title>New Document</title></head><body>Hello, world</body></html>";
oNewDoc.write(sMarkup);
oNewDoc.close();
}
</script>
</head>
<body>
<h1>I just want to say</h1><br>
<!--Button will call the replace function and replace the current page with a new one-->
<input type ="button" value = "Finish Sentence" >
</body>
</html>

....

not only does the new window not replace the old one, but after loading the new document the browser (IE7 at least) immediatly navigates back to the first document.

Tags What's this?: Add a tag
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG