List of all parameters for window.open ()

Source: Internet
Author: User

Http://www.cnblogs.com/meil/archive/2006/07/28/462459.html "1, the most basic popup window code"
In fact, the code is very simple:
<script language= "JavaScript" >
<!--
window.open (' page.html ')
-
</SCRIPT>
Because it is a javascripts code, they should be placed in <script language= "JAVASCR

IPT "> Between tags and </script>. <!--and--it works for some versions of the browser that are low,

The code in the tag is not displayed as text in some old browsers. It's a good habit to develop.
window.open (' page.html ') is used to control the pop-up of a new window page.html if page.html

Not in the same path as the main window, you should specify the path, absolute path (http://) and relative path (..

/) are available.
You can use both single and double quotes, just don't mix.
This section of code can be added anywhere in the HTML,
Ody> can also, the sooner the earlier the execution, especially the page code long, and want to make the page pop up as far as possible to

Put it in front.

"2, after setting the popup window"
Let's talk about the settings for the popup window. Just add a little something to the code above.

Let's customize the appearance of this pop-up window, size, pop-up position to fit the specific page

Case

<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 ')
Write a line
-
</SCRIPT>

Parameter explanation:
<script language= "javascript" > JS script start;
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;


</SCRIPT> JS script End

"3. Use function to control popup 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>

A function Openwin () is defined here, and the function content is to open a window. Before calling it, there's no

Any use.
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 2 windows at the same time"
Change the source code slightly:
<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=1

XX, Left=100,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, Loca

Tion=no, Status=no "
Write a line
}
-
</script>
To avoid pop-up 2 window overlays, use top and left to control the pop-up position do not cover each other

。 Finally, the four methods mentioned above can be called.
Note: The name of the 2 windows (NewWindows and NewWindow2) is not the same, or altogether empty.

Ok?

"5, main window open file 1.htm, while pop-up small window page.html"

Add the following code 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 timing close Control"

Let's take some control of the popup window, and the effect will be better. If we take a short

The code joins the popup page (note that it is added to the page.html HTML, not the main page, otherwise

...), let it automatically turn off after 10 seconds isn't it cooler?
First, add the following code to the <script language= "JavaScript" >

function Closeit () {

SetTimeout ("Self.close ()", 10000)//MS

}

</script>
Then, with <body onload= "Closeit ()" > This sentence instead of page.html the central Plains have <bo

Dy> This sentence will be able to. (This sentence must not forget to write Ah!) The function of this sentence is to invoke the close window

The code for the port, and closes the window on its own after 10 seconds. )

"7. Add a Close button to the pop-up window"
<FORM>
<input type= ' BUTTON ' value= ' off ' onclick= ' window.close () ' >
</FORM>
Oh, now more perfect!

"8, included in 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>

Look at the code inside OpenWindow.document.write () is not the standard HTML? Just follow

Format to write more rows. Pay attention to one more label or one less tag and there will be an error. Remember to use

OpenWindow.document.close () is over.


"9, the ultimate application-popup window of the cookie control"

Recall, the above pop-up window is cool, but there is a little problem (immersed in joy, must

You didn't find it? For example, you put the above script in a page that needs to be frequently passed (such as the homepage),

So every time you refresh this page, the window will pop up once, is it annoying? :-(
Is there a 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 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

In this page, the window will never pop up again. The real pop-only-once!.

List of all parameters for window.open ()

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.