Windows.open ()

Source: Internet
Author: User

Citation:Window_open detailed
First, window.open () Support environment:
javascript1.0+/jscript1.0+/nav2+/ie3+/opera3+

Second, the basic grammar:
window.open (Pageurl,name,parameters)
which
Pageurl as child window path
Name is a child window handle
Parameters is the window parameter (each parameter is separated by commas)

Three, example:

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


After the script runs, Page.html will open in the new form NewWindow, with a width of 100, a height of 400, 0 pixels from the top of the screen, 0 pixels left on the screen, no toolbars, no menu bars, no scroll bars, no resizing, no address bar, no status bar. Please compare.
In the above example, there are a few parameters that are commonly used, and there are many other parameters, see four.

four, the parameters
Where yes/no can also use 1/0;pixel value for a specific value, unit pixels.

Parameters | Range of Values | Description

alwayslowered | yes/no | Specifies that the window is hidden after all windows
alwaysraised | yes/no | Specifies that the window hovers above all windows
depended | yes/no | Whether to close at the same time as the parent window
Directories | yes/no | NAV2 and 3 's catalog columns are visible
Height | Pixel value | Window height
hotkeys | yes/no | Set safe exit Hotkey in window without menu bar
Innerheight | Pixel value | The pixel height of the document in the window
Innerwidth | Pixel value | The pixel width of the document in the window
Location | yes/no | Whether the location bar is visible
MenuBar | yes/no | Whether the menu bar is visible
Outerheight | Pixel value | Set the pixel height of the window (including the decorative border)
Outerwidth | Pixel value | Set the pixel width of the window (including the 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 top edge of the screen
ScrollBars | yes/no | Whether the window can have a scroll bar
TitleBar | yes/no | Whether the window title bar is visible
Toolbar | yes/no | Whether window toolbars are visible
Width | Pixel value | The pixel width of the window
Z-look | yes/no | Whether the window is activated to float on top of other windows

=====================================================

"1, the most basic popup window code"
In fact, the code is very simple:

<script language= "JavaScript" >
<!--
window.open (' page.html ')
-
</SCRIPT>


Because it's a javascripts code, they should be placed between <script language= "JavaScript" > tags and </script>. <!--and is useful for browsers with low versions, where the code in the tags is not displayed as text in these old browsers. It's a good habit to develop.
window.open (' page.html ') is used to control the popup new window page.html, if page.html is not in the same path as the main window, 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,
"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 situation of the page.

<script language= " JavaScript ">&NBSP;
<!-- 
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 ')  
//write a line of  
-  
</script>


Parameter explanation:  
<script language= "javascript" > JS script start;  
window.open command to pop up a new window;  
' Page.html ' pop-up window filename;  
' NewWindow ' popup name (not filename), non-mandatory, available empty ' instead of;  
height=100 window height;  
Width= 400 window width;  
top=0 window is the pixel value above the screen,  
left=0 window is the pixel value 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 to allow the window size to be changed, yes to allow,  
Location=no whether the address bar is displayed, yes is allowed;  
Status=no Whether to display the information in the status bar (usually the file is already open), yes to allow;  
</SCRIPT> js script end  

"3, control pop-ups with functions"  

The following is a complete code.


<script language= "JavaScript" >&NBSP;
<!-- 
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 of  

//--> 
</script> 
</ head> 
<body onload= "Openwin ()" >&NBSP;
... Any page content ...  
</body> 


a function Openwin () is defined here, and the function content is to open a window. There is no use before calling it.  
How do I call it?  
Method One: <body onload= "Openwin ()" > Browser popup when reading a page;  
Method Two: <body onunload= "Openwin ()" > Popup window when the browser leaves the page;  
Method Three: Call with a connection:  
<a href= "#" onclick= "Openwin ()" > Opens a window </a> 
Note: The "#" used is a virtual connection.  
Method Four: Call with a button:  
<input type= "button" onclick= "Openwin ()" value= "open Window" >&NBSP;

"4, pop up 2 windows simultaneously" &NBSP;

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=no, 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, Location=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 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 add a little piece of code to the pop-up page (note that it's added to Page.html's HTML, not the main page, otherwise ...), will it be cooler to turn it off automatically after 10 seconds?
First, add the following code to the


<script language= "JavaScript" >
function Closeit ()
{SetTimeout ("self.close ()", 10000)//msec}
</script>


Then, and then use <body onload= "Closeit ()" > This sentence instead of page.html Zhongyuan Some <BODY> this sentence can be. (This sentence must not forget to write Ah!) The function of this sentence is to invoke the code that closes the window, and then close 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" >&NBSP;
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" >&NBSP;
</body> 


Look at the code inside OpenWindow.document.write () 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 application-popup window of the cookie control" &NBSP;

Recall that the above pop-up window is cool, but a little bit of a problem (immersed in joy, must not find it?) For example, if you put the above script in a page that needs to be frequently passed (such as the homepage), then each time you refresh the page, the window will pop up once, is it annoying? :-(, is there a way out? 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" &NBSP;


</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. The real pop-only-once!.
Write here pop-up window of the production and application skills is basically finished, I was tired, said in a breath so much, I hope to be making a Web site friends have helped me very gratified.
It is important to note that the case in the JS script is best and always consistent.

Windows.open ()

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.