Window. open () parameter list

Source: Internet
Author: User

This article is an old blog from juyou.Window. open () parameter listBecause the old blog is no longer updated, and this article requires a lot of people, it will be reposted here. Things are older, but they are still the same practical. Next let's go to the topic:Window. open () parameter list:

[1. The most basic pop-up window Code]

In fact, the code is very simple:

Program code: [Copy code to clipboard]

 

<Script language = "javascript">

<! --

Window. open ('page.html ')

-->

</SCRIPT>

Because it is a piece of javascripts code, they should be placed between the <script language = "javascript"> tag and </script>. <! -- And --> are used for some earlier browsers, and the code in the labels is not displayed as text in these old browsers. This is a good habit. Window. open ('page.html ') is used to control the pop-up window page.html. If page.html is not in the same path as the main window, the path, absolute path (http: //), and relative path (../) should be specified before.

You can use single quotes and double quotes, but do not mix them. This piece of code can be added to any location of HTML, either between

[2. After setting, the pop-up window is displayed]

Let's talk about the settings in the pop-up window. You just need to add something to the code above.

We will customize the appearance, size, and position of the pop-up window to adapt to the specific situation of the page.

Program code: [Copy code to clipboard]

 

<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 = no, status = no ')

// Write a row

-->

</SCRIPT>

 

Parameter description:

<Script language = "javascript"> the js SCRIPT starts;

Window. open command to pop up a new window;

'Page.html 'name of the pop-up window;

'Newwindow' indicates the name of the pop-up window (not the file name). It is optional and can be replaced by null;

Height = 100 window height;

Width = 400 window width;

Top = the pixel value between the 0 window and the top of the screen;

Left = 0 the pixel value between the window and the left of the screen;

Toolbar = no indicates whether to display the toolbar. yes indicates display;

Menubar and scrollbars indicate the menu bar and scroll bar.

Resizable = no: whether to change the window size. yes: yes;

Location = no indicates whether the address bar is displayed. yes indicates yes;

Status = no whether to display the information in the status bar (usually the file has been opened), yes is allowed;

</SCRIPT> end of js SCRIPT

[3. Function Control pop-up window]

The following is a complete code.

Program code: [Copy code to clipboard]

 

<Html>

<Head>

<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 row

}

// -->

</Script>

</Head>

<Body onload = "openwin ()">

... Any page content...

</Body>

</Html>

 

A function openwin () is defined here, and the function content is to open a window. No

For any purpose.

How to call it?

Method 1: <body onload = "openwin ()"> A window pops up when the browser reads the page;

Method 2: <body onunload = "openwin ()"> A window pops up when the browser leaves the page;

Method 3: call with a connection:

<A href = "#" onclick = "openwin ()"> open a window. </a>

Note: "#" is a virtual connection.

Method 4: call with a button:

<Input type = "button" onclick = "openwin ()" value = "open window">

4. Two windows are displayed at the same time]

Slightly modify the source code:

Program code: [Copy code to clipboard]

 

<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 row

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 row

}

// -->

</Script>

To avoid overwriting the two pop-up windows, use top and left to control the position of the pop-up window. Finally, use the four methods mentioned above to call.

Note: The names of the two windows (newwindows and newwindow2) must not be the same, or they are all empty.

OK?

Open the file 1.htmin the main window, and pop up the window page.html at the same time]

Add the following code to the

Program code: [Copy code to clipboard]

 

<Script language = "javascript">

<! --

Function openwin (){

Window. open ("page.html", "", "width = 200, height = 200"

}

// -->

</Script>

Add to the <body> area:

<A href = "1.htm" onclick =" openwin () "> open </a>.

[6. timed close control for the pop-up window]

Next we will make some control over the pop-up window, and the effect will be better. If we add the field code to the page that pops up (the page is added to the HTML of page.html, not the page, otherwise...), will it be cool to enable it to be automatically disabled in 10 seconds?

First, add the following code to the

Program code: [Copy code to clipboard]

 

<Script language = "JavaScript">

Function closeit (){

SetTimeout ("self. close ()", 10000) // millisecond

}

</Script>

Then, use <body onload = "closeit ()"> to replace the original <BODY> sentence in page.html. (Do not forget to write this sentence! The function of this statement is to call the code for closing the window. The window will be closed in 10 seconds .)

7. Add a close button in the pop-up window]

<FORM>

<Input type = 'button 'value = 'close 'onclick = 'window. close ()'>

</FORM>

Now it's more perfect!

[8. included pop-up window-one page and two windows]

The preceding example contains two windows: one is the main window and the other is the small window that appears.

Through the example below, you can complete the above effect on a page.

Program code: [Copy code to clipboard]

 

<Html>

<Head>

<Script language = "JavaScript">

Function openwin ()

{

OpenWindow = window. open ("", "newwin", "height = 250, width = 250, toolbar = no <BR>, SCROLLBARS = "+ SCROLL +", MENUBAR = NO "; & NBSP;

// Write a row

Openmediaworkflow Doc ument. write ("<TITLE> example </TITLE>"

Openmediaworkflow Doc ument. write ("<body bgcolor = # ffffff>"

Openmediaworkflow Doc ument. write ("

Openmediaworkflow Doc ument. write ("New window opened! "

Openmediaworkflow Doc ument. write ("</BODY>"

Openmediaworkflow Doc ument. write ("</HTML>"

Openmediaworkflow Doc ument. close ()

}

</SCRIPT>

</Head>

<Body>

<A href = "#" onclick = "openwin ()"> open a window. </a>

<Input type = "button" onclick = "openwin ()" value = "open window">

</Body>

</Html>

 

Check if the code in openmediaworkflow Doc ument. write () is not standard HTML? You only need to write more rows according to the format. An error occurs when you add one or more labels. Remember to end with opentracing upload Doc ument. close.

[9. Ultimate application-Cookie control in the pop-up window]

In retrospect, although the pop-up window above is cool, there is a little bit of a problem (immersed in joy, do not find it ?) For example, if you place the above script in a page that requires frequent access (such as the homepage), the window will pop up every time you refresh the page, isn't it very annoying? :-(Is there a solution? Yes! ;-) Follow me.

We can use cookies to control it.

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

Program code: [Copy code to clipboard]

 

<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, use <body onload = "loadpopup ()"> (not openwin, but loadpop !)

Replace the original <BODY> sentence on the home page. You can refresh the page or enter the page again, and the window will no longer pop up. Real Pop-Only-Once!

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.