JavaScript window.open () property

Source: Internet
Author: User

A. Window Object

The Window object is the top-level object in the JavaScript hierarchy.

The Window object represents a browser window or a frame.

The Window object is automatically created each time <body> or <frameset> appears.

Two.

The open () method opens a new browser window or looks for a named window.

Three.

window.open (Url,name,features,replace)

Parameters Description
Url An optional string that declares the URL of the document to display in a new window. If this argument is omitted, or if its value is an empty string, then the new window will not display any documents.
Name An optional string that is a comma-delimited list of features, including numbers, letters, and underscores that declare the name of the new window. This name can be used as the value of the tag <a> and <form> property target. If the parameter specifies a window that already exists, the open () method no longer creates a new window, but simply returns a reference to the specified window. In this case, the features will be ignored.
Features An optional string that declares the characteristics of the standard browser to be displayed for the new window. If this argument is omitted, the new window will have all the standard features. In this table of window features, we describe the format of the string in detail.
Replace

An optional Boolean value. Specifies whether the URL loaded into the window creates a new entry in the window's browsing history or replaces the current entry in the browsing history. The following values are supported:

  • True-url replaces the current entry in the browsing history.
  • False-url creates a new entry in the browsing history.

Four. Window features (Windows Features)

Channelmode=yes|no|1|0 Whether to use the theater Mode Display window. The default is No.
Directories=yes|no|1|0 Whether to add a catalog button. The default is yes.
Fullscreen=yes|no|1|0 Whether to use full-screen mode to display the browser. The default is No. A window in full-screen mode must be in theater mode at the same time.
Height=pixels The height of the window document display area. measured in pixels.
Left=pixels The x-coordinate of the window. measured in pixels.
Location=yes|no|1|0 Whether the Address field is displayed. The default is yes.
Menubar=yes|no|1|0 Whether the menu bar is displayed. The default is yes.
Resizable=yes|no|1|0 Whether the window can be adjusted for size. The default is yes.
Scrollbars=yes|no|1|0 Whether scroll bars are displayed. The default is yes.
Status=yes|no|1|0 Whether to add a status bar. The default is yes.
Titlebar=yes|no|1|0 Whether the title bar is displayed. The default is yes.
Toolbar=yes|no|1|0 Whether to display the browser's toolbar. The default is yes.
Top=pixels The y-coordinate of the window.
Width=pixels The width of the document display area of the window. measured in pixels.

Five.

Attention:

window.open (Url,name,features,replace)

If name already exists with name, a new window is not created and a reference to the existing window is returned.

Otherwise, a new window is created.

I just didn't pay attention to it, and it took a lot of time to get the page full-screen.

Six. Specific business functions

6.1 Open a full-screen window

<script type= "Text/javascript" >

window.open ("http://google.com/", ' new Open Googlewin ', "fullscreen=1")

</script>

6.2 Make this page full screen

Solution: Open a full-screen target window first, and then close this window.

Code:

<script type= "Text/javascript" >

var url=document.location.href; Get the property name of this window
Newwin=window.open (URL, ' ', ' fullscreen=1,scrollbars=0 ');
window.opener=null;//out the prompt window when closing
window.open (', ' _self '); Ie7
Window.close ();

</script>

Note: If you specify the second argument in the open method and give him a specific value, the second time you use the method above, you will not be able to create a new window because the default return of the system already exists for the index of the window.

Press ESC to exit full screen

<script type= "Text/javascript" >

ESC exits full Screen
function Exitfullscreenme ()
{
var Esc=window.event.keycode;
if (esc==27)//Determines whether the ESC key is pressed, 27 represents the ESC key of the KeyCode.
{
var url=document.location.href;

Win=window.open (URL, ' ', ' Fullscreen=0,directories=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1, Titlebar=1,toolbar=1 '); Make the newly opened window full screen

window.opener=null;//out the prompt window when closing
window.open (', ' _self ');//ie7
Window.close (); Close the old window first

}
}
Document.onkeydown = Exitfullscreenme; Call Hotkey function when onkeydown (key trigger) event occurs

</script>

6.3 Pop-up two windows at a time

<script type= "Text/javascript" >

window.open ("http://google.com/", ' new Open googleWin1 ', "height=300, width=300, Top=0, Left=0,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, location=n O, Status=no ")

window.open ("http://google.com/", ' new Open googleWin2 ', "height=300, width=300, Top=0, Left=400,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, location=n O, Status=no ")
</script>

Note: (1) The name of the window cannot be the same, but it can be empty;

(2) Pay attention to the layout of two windows, whether it meets your requirements.

6.4

The first time you enter the page, the window pops up. Cookie resolution

First, add the following code to the <HEAD> area of the main page HTML:

<script>
function Openwin () {
window.open ("page.html", "", "width=200,height=200")
}
function Get_cookie (Name) {
var search = Name + "="
var returnvalue = "";
if (Document.cookie.length > 0) {
offset = document.cookie.indexOf (search)
if (offset! =-1) {
Offset + = Search.length
End = Document.cookie.indexOf (";", offset);
if (end = =-1)
end = Document.cookie.length;
Returnvalue=unescape (document.cookie.substring (offset, end))
}
}
Return returnvalue;
}
function Loadpopup () {
if (Get_cookie (' popped ') = = ") {
Openwin ()
Document.cookie= "Popped=yes"
}
}
</script>

Then, with <body onload= "Loadpopup ()" > (note not openwin but Loadpop!) Replace the main Page <BODY> this sentence can be. You can try refreshing this page or re-entering the page, and the window will never pop up again.

JavaScript window.open () property

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.