window.open () method parameters in detail 1, the most basic popup window code
window.open (' page.html ');
2, after setting the pop-up window
window.open (' page.html ', ' newwindow ', ' height=100, width=400, Top=0, left=0, Toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, Location=no, Status=no ')//The sentence is written in a line of code
Parameter explanation:
window.open the command that pops up the new window;
The filename of the ' page.html ' pop-up window;
The name of the ' NewWindow ' pop-up window (not the file name), not required, available empty ' ' 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 is displayed;
Menubar,scrollbars represents the menu bar and scroll bar.
Resizable=no whether the window size is allowed to change, yes is allowed;
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 already open), yes is allowed;
3, use function to control pop-up window
The following is a complete code
<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 a line
}
-
</script>
<body onload= "Openwin ()" >
Any page content ...
</body>
Explanation: a function Openwin () is defined here, and the function content is to open a window. There is no use before calling it. How to invoke it?
Method One: <body onload= "Openwin ()" > Browser to read the page when the pop-up window;
Method Two: <body onunload= "Openwin ()" > Pop-up window when the browser leaves the page;
Method Three: Call with a connection:
<a href= "#" onclick= "Openwin ()" > Open a Window </a>
Note: The "#" used is a virtual connection.
Method Four: Call with a button:
<input type= "button" onclick= "Openwin ()" value= "open Window"/>
4, pop up two windows
Change the code slightly as follows:
<script language= "JavaScript" >
<!--
function Openwin () {
window.open ("page.html", "NewWindow", "height=100, width=100, Top=0, Left=0,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, location=n O, Status=no ")//write a line
window.open ("page2.html", "NewWindow2", "height=100, width=100, top=100, Left=100,toolbar=no, Menubar=no, scrollbars= No, Resizable=no, Loca Tion=no, Status=no ")//write a line
}
-
</script>
To avoid the pop-up of the 2 window overlay, use top and left to control the pop-up position do not cover each other. Finally, the above mentioned four methods are called.
Note: The name of the 2 windows (NewWindow and NewWindow2) is not the same, or altogether empty.
5, main window open file 1.htm, while pop-up small window page.html
Add the following code to the main window function Openwin ()
{
window.open ("page.html", "", "width=200,height=200")
}
To join the body area:
<a href= "1.htm" onclick= "Openwin ()" >open</a>.
6, pop-up window timed off control
Add a small piece of code to the popup page (note that adding page.html HTML is not the main page, otherwise ...). Is it cool to have it automatically shut down after 10 seconds?
function Closeit ()
{
SetTimeout ("Selft.close ()", 10000)//MS
}
Then, add in body: <body onload= "Closeit ()" >.
7, add a close button in the pop-up window
<input type= "button" value= "Close" onclick= "Window.close ()" >
8, contains the pop-up window---a page two windows
The example above contains two windows, one is the main window and the other is a small pop-up window. In the following example, you can perform the above effect on a page.
<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 </TITLE>")
OpenWindow.document.write ("<body bgcolor= #ffffff >")
OpenWindow.document.write ("OpenWindow.document.write ("New window opened!")
OpenWindow.document.write ("</BODY>")
OpenWindow.document.write ("</HTML>")
OpenWindow.document.close ()
}
</SCRIPT>
<body>
<a href= "#" onclick= "Openwin ()" > Open a Window </a>
<input type= "button" onclick= "Openwin ()" value= "open Window" >
</body>
OpenWindow.document.write () The code inside is not the standard HTML? Just write more lines in the format. Pay attention to one more label or one less tag and there will be an error. Remember to end with OpenWindow.document.close ().
9, the ultimate app---pop-up window this cookie control
Recall, although the above pop-up window is cool, but a little bit of a problem, such as you put the above script in a frequently required pages (such as the homepage), then each time you refresh the page, the window will pop up, is not very annoying?
Is there a way to solve it? We use cookies to control.
First, add the following code to the head area of the HTML on the main page:
function Openwin () {
window.open ("page.html", "", "width=200,height=200")
}
function Get_cookie (Name)
{
var search=name+ "=";
var returnvalue= "";
if (document.cookie.length>0) {
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 Ladpopup ()
{
if (Get_cookie (' Popped=yes '))
{
Openwin ()
Document.cookie= "Popped=yes";
}
}
Finally, use <body onload= "Loadpopup ()" >
Write to here pop-up window of the production and application skills are basically finished!
window.open () method parameters