JavaScript pop-up window window.open use method and parameter explanation analysis Article _ Basics

Source: Internet
Author: User
window.open use method and parameter description
First, window.open () Support environment:
javascript1.0+/jscript1.0+/nav2+/ie3+/opera3+
  
Second, the basic grammar:
  
window.open (Pageurl,name,parameters)
  
which
Pageurl as a child window path
Name is a child window handle
Parameters for window parameters (comma-separated arguments)
  
Third, the parameters
  
Where yes/no can also use 1/0;pixel value as the specific value, the unit pixel.
  
Parameters | Value Range | Description | |
alwayslowered | yes/no | Specifies that the window is hidden behind all windows
alwaysraised | yes/no | Specifies that the window is suspended above all windows
depended | yes/no | Whether to close the parent window at the same time
Directories | yes/no | Whether the NAV2 and 3 columns are visible
Height | Pixel value | Window height
hotkeys | yes/no | Set up a secure exit hotkey in a window without a menu bar
Innerheight | Pixel value | Pixel height of the document in the window
Innerwidth | Pixel value | Pixel width of the document in the window
Location | yes/no | Whether the position bar is visible
MenuBar | yes/no | Whether the menu bar is visible
Outerheight | Pixel value | Set the pixel height of a window (including a decorative border)

Outerwidth | Pixel value | Set the pixel width of a window (including a decorative border)
resizable | yes/no | Whether the window size can be adjusted
ScreenX | Pixel value | The pixel length of the window from the left edge of the screen
ScreenY | Pixel value | The pixel length of the window from the edge of the screen
ScrollBars | yes/no | Whether a window can have a scroll bar
TitleBar | yes/no | Whether the window topic bar is visible
Toolbar | yes/no | Whether the window toolbar is visible
Width | Pixel value | The pixel width of the window
Z-look | yes/no | Whether the window floats on top of other windows when it is activated
Below I will take you to dissect its mystery.
"1, the most basic pop-up window code"
In fact, the code is very simple:
<script language= "JavaScript" > <!--window.open (' page.html ')--> </SCRIPT>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Because it is a javascripts code, they should be placed in <script language= "JAVASCR
IPT "> Between label and </script>. <!--and--> are useful for some versions of browsers that do not display the code in the label as text in these old browsers. To develop this good habit ah.
window.open (' page.html ') is used to control pop-up new Windows page.html if page.html
Not in the same path as the main window, preceded by the path, absolute path (http://) and relative path (...
/) are available.
Both single and double quotes are OK, just don't mix.
This piece of code can be added anywhere in HTML,"2, after the Set pop-up window"
Let's say a pop-up window setting. Just add something to the code above.
Let's customize the appearance of this pop-up window, size, and popup position to fit the page's specifics.
<script language= "JavaScript" > <!--window.open (' page.html ', ' newwindow ', ' height=100, width=400, Top=0, left =0, Toolbar=no, Menubar=no, Scrollbars=no, resizable=no,location=n o, Status=no ')//written in one line--> </SCRIPT>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Parameter explanation:
<script language= "javascript" > JS script started;
window.open the command to eject a new window;
The filename of the ' page.html ' pop-up window;
' NewWindow ' pop-up window name (not filename), not required, available null ' instead;
height=100 window height;
width=400 window width;
The pixel value of the Top=0 window from the top of the screen;
The pixel value of the left=0 window from the left side of the screen;
Toolbar=no whether the toolbar is displayed, yes for display;
Menubar,scrollbars represents the menu bar and scroll bar.
Resizable=no whether to allow changes to the window size, yes to allow;
Location=no whether the address bar is displayed, yes is allowed;
Status=no whether the information in the status bar is displayed (usually the file is open), yes to allow;
</SCRIPT> JS script End
"3, control pop-up window with function"
The following is a complete code.
<ptml> <pead> <script language= "JavaScript" > <!--function Openwin () {window.open ("page.html", "NewWindow", "height=100, width=400, toolbar =no, Menubar=no, Scrollbars=no, Resizable=no, Location=no, Status=no")/write In one line}//--> </script> </pead> <body onload= "Openwin ()" > ... Any page content ... </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

A function Openwin () is defined here, and the function content is to open a window. There is no use before calling it.
How to call it?
Method One: <body onload= "Openwin ()" > Browser pop-up window when reading the page;
Method Two: <body onunload= "Openwin ()" > Browser out of the page pop-up window;
Method Three: Call with a connection:
<a href= "#" onclick= "Openwin ()" > Open a Window </a>
Note: The "#" used is a virtual connection.
Method Four: Use a button to invoke:
<input type= "button" onclick= "Openwin ()" value= "open Window" >
"4, pop-up 2 windows at the same time"
Change the source code a little bit:
<script language= "JavaScript" > <!--function Openwin () {window.open ("page.html", "NewWindow", "Height=100, W idth=100, Top=0, Left=0,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, location=n O, Status=no ")//written in one line WINDOW.O Pen ("page2.html", "NewWindow2", "height=100, width=100, Top=1, Left=100,toolbar=no, Menubar=no, Scrollbars=no, Resiz Able=no, Loca Tion=no, Status=no ")//written in one line}//--> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

To prevent the 2 windows from popping up, use top and left to control the pop-up position and not overwrite each other.
。 The last four methods mentioned above can be invoked.
Note: The name of the 2 windows (NewWindows and NewWindow2) is not the same, or simply all empty.
Ok?
"5, the main window to open the file 1.htm, while pop-up small Windows page.html"
The following code is added to the main window <script language= "JavaScript" >
<!--
function Openwin () {
window.open ("page.html", "" "," width=200,height=200 ")
}
-->
</script>
Join <body> Area:
<a href= "1.htm" onclick= "Openwin ()" >open</a>.
"6, pop-up window of the timing off control"
Below we have some control of the pop-up window, the effect is better. If we add a small piece of code to the pop-up page (note is added to the page.html HTML, not the main page, otherwise ...), let it automatically shut down in 10 seconds is it cooler?
First, add the following code to the <script language= "JavaScript" >
function Closeit () {
SetTimeout ("Self.close ()", 10000)//MS
}
</script>
Then, then use the <body onload= "Closeit ()" > This sentence instead of page.html central some <bo
Dy> this sentence is OK. (Don't forget to write this sentence!) The function of this sentence is to call the code that closes the window, and then close the window itself after 10 seconds. )
"7, add a Close button in the pop-up window"
<FORM>
<input type= ' BUTTON ' value= ' close ' onclick= ' window.close () ' >
</FORM>
Oh, now more perfect!
"8, included pop-up window-one page two windows"
The example above contains two windows, one is the main window and the other is a pop-up window.
With the example below, you can do the above in one page.
<textarea id="runcode94495"><ptml> <pead> <script language= "JavaScript" > Function Openwin () {Openwindow=window.open ("") "Newwin", "height=250, Width=250,toolbar=no, scrollbars=" +scroll+ ", Menubar=no"); Write a line OpenWindow.document.write ("<TITLE> example wind more ASP code generator </title>") OpenWindow.document.write ("<body bgcolor= #ffffff > ") OpenWindow.document.write (" <p>Hello!</p> ") OpenWindow.document.write (" New Window opened! ") OpenWindow.document.write ("</BODY>") OpenWindow.document.write ("</HTML>") OpenWindow.document.close ( )} </SCRIPT> </pead> <body> opens a window <input type= "button" onclick= "Openwin ()" value= "open Window" > </body> </ptml></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Look at the code inside OpenWindow.document.write () is not standard HTML? Just write more lines in the format. Be sure to pay attention to one more label or one less label will cause errors. Remember to end with OpenWindow.document.close ().
"9, the Ultimate application-pop-up window of the cookie control"
Recall that the above pop-up window, although cool, but there is a little trouble (immersed in joy, must not find it?) For example, you put the above script in a page that needs to go through frequently (for example, the first page), then each refresh this page, the window will pop up once, is not very annoying? :-( Is there any way to solve it? yes! ;-) Follow me.
We can use cookies to control it.
First, add the following code to the <HEAD> area of the homepage HTML:
<script> function Openwin () {window.open ("page.html", "", "width=200,height=200")} function Get_cookie (Name) {V AR search = Name + "=" var returnvalue = ""; if (Document.cookie.length > 0) {offset = document.cookie.indexOf (search) if (offset!=-1) {offset = Search.leng th 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>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Then, with <body onload= "Loadpopup ()" > (note not openwin but Loadpop!) )
Replace the main page in the original <BODY> this sentence can be. You can try to refresh the page or re-enter it.
Into the page, the window will never pop again. The real pop-only-once!.
Here's where the pop-up window's production and application techniques are almost complete.
Related Article

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.