Web design page Jump method, web page Jump
I. asp.net c # open a new page or jump to the page
1. The most common page Jump (the original window is replaced): Response. Redirect ("newpage. aspx ");
2. Use the url address to open a local webpage or the Internet: Respose. Write ("<script language = javascript> window. open (" + url + "); </script> ");
3. the original window is retained and another page is opened again (the browser may block it and you need to remove it): Response. write ("<script> window. open (newpage. aspx; _ blank;) </script> ");
4. Response. Write ("<script> window. location = newpage. aspx; </script> ");
5. The original window is also replaced (usually used to pass the page jump of the session variable): Server. Transfer ("newpage. aspx ");
6. Retain the original window and open a new window in the form of a dialog box: Response. Write ("<script> window. showModelessDialog ('main. aspx ') </script> ");
7. open a new window in the dialog box. The original window is replaced by: Response. Write ("<script> window. showModelDialog ('main. aspx ') </script> ");
8. open the concise window: Respose. write ("<script language = 'javascript '> window. open ('"+ url +"', resizable = 1, scrollbars = 0, status = 1, menubar = no, toolbar = no, location = no, menu = no ;); </script> ");
2. Open a new page or jump to the page through javascript
1. directly jump to the original form using
Onclick = function (){
Window. location. href = "main. aspx ";
};
2. Open the page in the new form:
Onclick = function (){
Window. open ("main. aspx ");
};
3. Return to the previous page (the local test may be invalid and available on the server)
Window. history. back (-1 );
<A onclick = "javascript: history. back (1);" href = "#"> return </a>
<A href = "javascript: history. go (-1)"> return to the previous page </a>
<A href = "<% = Request. ServerVariables (" HTTP_REFERER ") %>"> back to previous page </a>
4. Some Usage
License:
<INPUT name = "pclog" type = "button" value = "axmanhz blog" onClick = "location. href = 'Connection address';">
Direct jump:
<Script> window. location. href = "connection address"; </script>
Open a new window:
<A href = "javascript:" onClick = "window. open ('Connection address'; height = 500, width = 611, scrollbars = yes, status = yes) "> 123 </a>
Automatically open <SCRIPT>
<! --
Window. open ("connection address", "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 the script is run, the "connection address" will be opened in the newwindow of the new form. The value is 100 in width, 400 in height, 0 pixels from the screen top, 0 pixels left, no tool bar, and 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.
▲Parameter descriptions
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]
Automatic pop-up
<Script language = "javascript">
<! --
Window. open ("connection address ")
-->
</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 ("connection address") is used to control the pop-up window. If the pop-up window is not in the same path as the main window, specify the path and absolute path (http ://) and relative path (... 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.
Automatic pop-up
<Script language = "javascript">
<! --
Window. open ("link address", "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;
The file name in the "link address" pop-up window;
"Newwindow" Name of the pop-up window (not a file name), not required, can be blank;
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 ("link address", "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]
Slightly modify the source code:
<Script LANGUAGE = "JavaScript">
<! --
Function openwin (){
Window. open ("link address 1", "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 ("link address 2", "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 the field code to the page that pops up (the page is added to the HTML of page.html, not the page, or else...), will it be cool to enable it to be automatically disabled 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 ("</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>
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]
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:
<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 = (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!