Oh, there are some items in the pop-up window ~

Source: Internet
Author: User

Note:
// Close. The parent window dialog box is displayed, and the Child window is closed directly.
This. response. Write ("<script language = JavaScript> window. Close (); </SCRIPT> ");

// Close. The parent window and Child Window are not displayed. Close them directly.
This. response. Write ("<SCRIPT> ");
This. response. Write ("{top. Opener = NULL; top. Close ();}");
This. response. Write ("</SCRIPT> ");

// In the pop-up window, refresh the current page width = 200 Height = 200 menu. Menu Bar, tool bar, address bar, and status bar none
This. response. write ("<script language = JavaScript> window. open ('rows. aspx ', 'newwindow', 'width = 200, Height = 200') </SCRIPT> ");

// Refresh the current page in the pop-up window
This. response. Write ("<script language = JavaScript> window. Open ('rows. aspx ') </SCRIPT> ");
This. response. Write ("<SCRIPT> window. Open ('webform2. aspx ',' _ blank '); </SCRIPT> ");

// In the pop-up window, jump to the webform2.aspx page (in an IE window)
This. response. write ("<script language = JavaScript> alert ('registered successfully'); window. window. location. href = 'webform2. aspx '; </SCRIPT> ");

// Close the current Child Window and refresh the parent window
This. response. Write ("<SCRIPT> window. opener. Location. href = Window. opener. Location. href; window. Close (); </SCRIPT> ");
This. response. Write ("<SCRIPT> zookeeper opener.location.replace(w.w.opener.doc ument. referrer); window. Close (); </SCRIPT> ");

// Refresh the parent window in the Child Window
This. response. Write ("<SCRIPT> window. opener. Location. href = Window. opener. Location. href; </SCRIPT> ");
This. response. Write ("<SCRIPT> window. opener. Location. href = 'webform1. aspx '; </SCRIPT> ");

// A prompt window is displayed. After confirmation, A subwindow (webform2.aspx) is displayed)
This. response. Write ("<script language = 'javascript '> alert (' published successfully! '); Window. Open ('webform2. aspx') </SCRIPT> ");

// A prompt window is displayed. After confirmation, refresh the parent window.
This. response. Write ("<SCRIPT> alert ('published successfully! '); Window. opener. Location. href = Window. opener. Location. href; </SCRIPT> ");

// The Same page is displayed.
<Input type = "button" value = "button" onclick = "javascript: window. Open (window. Location. href)">

//
Response. Write ("parent. mainframebottom. Location. href = 'yourwebform. aspx? Temp = "+ STR + "';");


parameter explanation:
end of JS script

'Newwin': hides the toolbar in the menu bar's address bar.
Width = 50: width
Height = 50: Height
Scrollbars = yes/no: scroll bar
Top = 50: the window is above the screen
Left = 50: the window is located at the left of the screen.
Example: window. Open ('detail. aspx? Id = "+ E. item. cells [1]. text + "', 'newwin', 'width = 750, Height = 600, scrollbars = Yes, Top = 50, Left = 50 ');");
This. response. write ("<SCRIPT> window. open ('webform2. aspx ', '', 'toolbar = No, location = No, directories = No, status = No, menubar = No, scrollbars = No, resizable = Yes, width = 750, height = 470, Left = 80, Top = 40'); </SCRIPT> ");

Example:
This. response. Write ("<SCRIPT> alert ('published successfully! '); Window. opener. Location. href = Window. opener. Location. href; </SCRIPT> ");
This. response. Write ("<SCRIPT> ");
This. response. Write ("{top. Opener = NULL; top. Close ();}");
This. response. Write ("</SCRIPT> ");

Example: linkcolumn1.datanavigateurlformatstring = "javascript: varwin = Window. Open ('edit _ USR. aspx? Actid = {0} ', 'newwin', 'width = 750, Height = 600, scrollbars = Yes, Top = 50, Left = 50'); window. close ()";

This. response. write ("<SCRIPT> window. open ('webform7. aspx ', '', 'toolbar = No, location = No, directories = No, status = No, menubar = No, scrollbars = No, resizable = Yes, width = 750, height = 470, Left = 80, Top = 40'); </SCRIPT> ");

Whether the pop-up is related to the menu Toolbar of your current window. You only need to write a script on the page and it will pop up. For example
<A href = # onclick = "window. Open ('xxx. aspx ', 'window name', 'parameter');"> XXXXX </a>

The following lists the parameters in the pop-up window. You can set them by yourself. The parameters are separated by commas.

Optional. String-list object tables and separate them with commas. Each item has its own value, which will be separated (for example, "fullscreen = Yes, toolbar = yes "). The following are supported features.
Channelmode = {Yes | no | 1 | 0} indicates whether the tier mode is displayed in the window. The default value is no.
Directories = {Yes | no | 1 | 0} whether various buttons are displayed in the window. The default value is yes.
Fullscreen = {Yes | no | 1 | 0} whether to display the browser in full screen mode. The default value is no. Be careful when using this feature. This property may hide the title bar and menu of the browser. You must provide a button or other prompt to help the user close the browser window. Alt + F4 can close the window. A full screen window must be in the channelmode mode.
Height = number indicates the window height, in pixels. Minimum value: 100.
Left = number indicates the distance from the window to the left border, in pixels. The value must be greater than or equal to 0.
Location = {Yes | no | 1 | 0} specifies whether to display the address bar in the window. The default value is yes.
Menubar = {Yes | no | 1 | 0} specifies whether to display the menu bar in the window. The default value is yes.
Resizable = {Yes | no | 1 | 0} specifies whether to display the handle that can be adjusted in the window. The default value is yes.
Scrollbars = {Yes | no | 1 | 0} specifies whether the horizontal or vertical scroll bar is displayed in the window. The default value is yes.
Status = {Yes | no | 1 | 0} specifies whether to display the status bar in the window. The default value is yes.
Titlebar = {Yes | no | 1 | 0} specifies whether to display the title bar in the window. This option is ignored when HTML application or a dialog box is not called. The default value is yes.
Toolbar = {Yes | no | 1 | 0} specifies whether to display the toolbar in the window, including buttons such as forward, backward, and stop. The default value is yes.
Top = Number specifies the position at the top of the window, in pixels. The value must be greater than or equal to 0.
Width = number indicates the window width in pixels. Minimum value: 100.

[1. Basic pop-up window Code ]

<Script language = "JavaScript">
<! --
Window. Open ('page.html ')
-->
</SCRIPT>

Because this is a piece of javascripts code, they should be placed between the <script language = "JavaScript"> label 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.

<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 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.
<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. There is no purpose before calling it. 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]

Pair Source code Slightly changed:

<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 row
Window. open ("page2.html", "newwindow2", "Height = 100, width = 100, Top = 1 00, Left = 100, toolbar = No, menubar = No, scrollbars = No, resizable = No, loca tion = 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.

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 <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 a small piece of code to the pop-up page (HTML is added to page.html, not the homepage), will it be cool to enable the code to be automatically disabled 10 seconds later?
First, add the following code to the <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.

<HTML>
<Head>
<Script language = "JavaScript">
Function openwin ()
{
OpenWindow = Window. Open ("", "newwin", "Height = 250, width = 250, toolbar = No, scrollbars =" + scroll + ", menubar = No ");
// Write a row
Opendeskdoc 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 ("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>

Do you think 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 openmediaworkflow Doc ument. Close.

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

Recall that the pop-up window above is cool, but it has a slight problem. For example, if you place the above script in a page that requires frequent passing (such as the homepage), refresh the page each time, the window will pop up once. We can use cookies to control it.
First, add the following code to the

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