[Reprinted] ASP. NET closes the current window and opens a new window

Source: Internet
Author: User

First, write the following in pageload:Code: Response. Write ("<SCRIPT> window. Opener = NULL; window. Close (); </SCRIPT> ");

Next, write the following js code in the head: <script language = "JavaScript">
<! --
Function openwin () {window. open ("default. aspx "," newwindow "," Height = 600, width = 600, toolbar = No, menubar = No, scrollbars = No, resizable = No, location = No, status = No ")
// Write a row
}
-->
</SCRIPT>

Finally, call the openwin () method in the body: <body onUnload = "openwin ()">

Response. Write ("<SCRIPT> window. Close (); </SCRIPT>"); // you can check whether to disable the function.
Response. Write ("<SCRIPT> window. Opener = NULL; window. Close (); </SCRIPT>"); // No query is displayed.

Window. open () details are as follows:

I. Windows. open () support environment:
Javascript1.0 +/jscript1.0 +/nav2 +/ie3 +/opera3 +

Ii. Basic Syntax:
Window. Open (pageurl, name, parameters)
Where:
Pageurl is the sub-window path
Name is the sub-window handle
Parameters is window parameters (parameters are separated by commas)

Iii. 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 row
-->
</SCRIPT>

After running the script, page.html will be opened in the newwindow of the new form, with a width of 100, a height of 400, 0 pixels at the top of the screen, and 0 pixels at the left of the screen

, No tool bar, no menu bar, no scroll bar, no size adjustment, no address bar, no status bar. Please compare.
In the preceding example, several common parameters are involved. In addition, there are many other parameters. For details, see section 4.

Iv. Parameters
Here, yes/no can also use 1/0; pixel value is a specific value, in pixels.

Parameter | value range | description

Alwayslowered | yes/no | specifies that the window is hidden behind all windows
Alwaysraised | yes/no | specify that the window is suspended above all windows
Depended | yes/no | whether to close the parent window at the same time
Directories | yes/no | whether the directory bar of nav2 and 3 is visible
Height | pixel value | window height
Hotkeys | yes/no | set the Security Exit hotkey in the window without menu bar
Innerheight | pixel value | pixel height of the document in the window
Innerwidth | pixel value | 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 | pixel length between the window and the left boundary of the screen
Screeny | pixel value | pixel length between the window and the upper boundary of the screen
Scrollbars | yes/no | whether the window has a scroll bar
Titlebar | yes/no | whether the title bar of the window is visible
Toolbar | yes/no | whether the toolbar of the window is visible
Width | pixel value | pixel width of the window
Z-Look | yes/no | whether the window floated above other windows after being activated

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

[1. The most basic pop-up window Code]
In fact, the code is very simple:
<Script language = "JavaScript">
<! --
Window. Open ('page.html ')
-->
</SCRIPT>

Because it is a piece of javascripts code, they should be placed in the <script language = "JavaScript"> label and

</SCRIPT>. <! -- And --> are used for Some browsers with low versions. In these old browsers, the code in the tag is not

Is displayed as text. This is a good habit.
Window. Open ('page.html ') is used to control the new window page.html. If page.html is not the same as the main window

Path, you must specify the absolute path (http: //) and relative path. You can use single quotes and double quotes, but do not

Mix.
This piece of code can be added to any HTML location, either between

Early execution, especially the long Page code. If you want the page to pop up early, try to move it forward.

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

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

PairSource codeSlightly 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 = 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, we use

You can call these four methods.
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

<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 short piece of code to the pop-up page (

Tags are added to the HTML of page.html, but not on the homepage. Otherwise ...), Is it cool to enable automatic shutdown in 10 seconds?
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>

Check if the code in openmediaworkflow Doc ument. Write () is not standard HTML? You only need to write more rows in 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, you

Place the above script in a page that requires frequent passing (such as the homepage), the window will pop up every time this page is refreshed,

Is it annoying? :-(Is there a solution? Yes! Follow me.
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 original on the home page

<Body> This sentence is enough. You can refresh the page or enter the page again, and the window will no longer pop up. Real pop

-Only-once!
The creation and application skills of the pop-up window are basically completed, and I am exhausted. I have said so much in one breath and hope

I am very pleased that my friends who have made web pages have helped me.
It should be noted that the case sensitivity in JS scripts should be consistent before and after

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.