JavaScript application in asp.net

Source: Internet
Author: User
Close, Parent window pop-up dialog box, child window close directly
This. Response.Write ("<script language=javascript>window.close ();</script>");
Close, neither the parent window nor the child window pops up the dialog box and closes directly
This. Response.Write ("<script>");
This. Response.Write ("{Top.opener =null;top.close ();}");
This. Response.Write ("</script>");
Pop-up window refreshes the current page width=200 height=200 menu. menu bar, toolbar, address bar, status bar all without
This. Response.Write ("<script Language=javascript>window.open
(' rows.aspx ', ' newwindow ', ' width=200,height=200 ') </script>);
Pop-up window refreshes the current page
This. Response.Write ("<script language=javascript>window.open (' rows.aspx ') </script>");
This. Response.Write ("<script>window.open" (' webform2.aspx ', ' _blank ');</script> ");
Pop-up prompt window jumps to webform2.aspx page (in an IE window)
This. Response.Write ("<script Language=javascript>alert" ("registered as
Work "); Window.window.location.href= ' webform2.aspx '";</script> ");
Closes the current child window and refreshes the parent window
This. Response.Write
("<script>window.opener.location.href=window.opener.location.href;window.close
();</script> ");
This. Response.Write ("<script>window.opener.location.replace
(window.opener.document.referrer); Window.close ();</script> ");
child window refreshes parent 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>");
Pop-up prompt window. OK popup child window (webform2.aspx)
This. Response.Write ("<script language= ' JavaScript") >alert ("published successfully.") "); window.open
(' webform2.aspx ') </script> ");
Pop-up Prompt window, OK, refresh parent window
This. Response.Write ("<script>alert", published as
Work. ");window.opener.location.href=window.opener.location.href;</script>");
The same page pops up
<input type= "button" value= "button" onclick= "Javascript:window.open (window.location.href)" >
//
Response.Write ("parent.mainframebottom.location.href= ' yourwebform.aspx?temp=" +str+ ";");

<script language= "JavaScript" >
<!--
window.open (' page.html ', ' newwindow ', ' height=100, width=400, Top=0, left=0,
Menubar=no, Scrollbars=no, resizable=no,location=n o, Status=no ')//This sentence is to be written in one line
-->
</SCRIPT>
  
Parameter explanation:
  
<script language= "javascript" > JS script started;
window.open the command to eject a new window;
' page.html ' pop-up window filename;
' NewWindow ' pop-up window name (not file name), not required, free "" "instead;
height=100 window height;
width=400 window width;
The pixel value of the Top=0 window from the top of the screen;
The pixel value of the left=0 window from the left side of the screen;
Toolbar=no whether the toolbar is displayed, yes for display;
Menubar,scrollbars represents the menu bar and scroll bar.
Resizable=no whether to allow changes to the window size, yes to allow;
Location=no whether the address bar is displayed, yes is allowed;
Status=no whether the information in the status bar is displayed (usually the file is open), yes to allow;
</SCRIPT> JS script End
' Newwin ': Hide menu bar Address bar toolbar
WIDTH=50: Width
HEIGHT=50: Height
Scrollbars=yes/no: Scroll bar
TOP=50: Window from the top of the screen
LEFT=50: Window from left side of 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=n
O,resizable=yes,width=750,height=470,left=80,top=40 ');</script> ");
Cases:
This. Response.Write ("<script>alert", published as
Work. ");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=n
O,resizable=yes,width=750,height=470,left=80,top=40 ');</script> ");
Pop-up is not related to your current window has no menu toolbar, you just write a script in the page it pops up.
<a href=# onclick= "window.open (' xxx.aspx ', '" ' Window name ', ' ' parameter '); " >xxxxx</a>
Here are some pop-up window parameters that you can set, separated by commas
Optional. String--Lists the object tables and separates them with commas. Each item has its own value, they will be separated (such as: "Fullscreen=yes,
Toolbar=yes "). Here are the various features that are supported.
Channelmode = {Yes | no | 1 | 0} Whether the step mode is displayed in the window. The default is No.
directories = {Yes | no | 1 | 0} whether to display various buttons in the window. The default is yes.
fullscreen = {Yes | no | 1 | 0} whether the browser is displayed in Full-screen mode. The default is No. Using this feature requires a very
Be careful. Because this property may hide the browser's title bar and menu, you must provide a button or other hint to help the user
Closes this browsing window. ALT+F4 can close the window. A full-screen window must use the step (channelmode) mode.
Height = number Specifies the height of the window, in pixels. The minimum value is 100.
left = number Specifies the distance, in pixels, of the window from the left-hand border. Value must be greater than or equal to 0.
Location = {Yes | no | 1 | 0} Specifies whether the address bar is displayed in a window. The default is yes.
menubar = {yes | no | 1 | 0} Specifies whether the menu bar is displayed in a window. The default is yes.
resizable = {Yes | no | 1 | 0} Specifies whether a handle that can be resized by the user is displayed in the window. The default is yes.
scrollbars = {yes | no | 1 | 0} Specifies whether to display a horizontal or vertical scroll bar in a window. The default is yes.
Status = {Yes | no | 1 | 0} Specifies whether the status bar is displayed in the window. The default is yes.
titlebar = {Yes | no | 1 | 0} Specifies whether the title bar is displayed in the window. In an application HTML or a
dialog box, this item will be ignored. The default is yes.
toolbar = {Yes | no | 1 | 0} Specifies whether to display a toolbar in a window, including buttons such as forward, rewind, stop, and so on. Implied
Think yes.
top = number Specifies the position, in pixels, of the tip of the window. Value must be greater than or equal to 0.
width = number Specifies the breadth of the window, in pixels. The minimum value is 100.
"1, the most basic pop-up window code"
  
<script language= "JavaScript" >
<!--
window.open (' page.html ')
-->
</SCRIPT>
  
Because this is a javascripts code, they should be placed in <script language= "JavaScript" > tags and
Between </script>. <!--and--> are working with a few versions of browsers that do not use the code in the tags in these old browsers
is displayed for the text. To develop this good habit ah. window.open (' page.html ') is used to control pop-up new Windows page.html
, if the page.html is not in the same path as the main window, precede the path, the absolute path (http://), and the relative path (...). /) are available
。 Both single and double quotes are OK, just don't mix. This piece of code can be added to any location in HTML,Between the,<body> </body> can also be, the more early implementation, especially the length of the page code, but also want to make the page early pop-up as far as possible forward
Put
 
"2, after the Set pop-up window"
  
Let's say a pop-up window setting. Just add something to the code above. Let's customize this pop-up.
The appearance, size, and popup position of the window to fit the page's specifics.
  
<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 ')//This sentence is to be written in a
Yes
-->
</SCRIPT>
  
Parameter explanation:
  
<script language= "javascript" > JS script started;
window.open the command to eject a new window;
' page.html ' pop-up window filename;
' NewWindow ' pop-up window name (not file name), not required, free "" "instead;
height=100 window height;
width=400 window width;
The pixel value of the Top=0 window from the top of the screen;
The pixel value of the left=0 window from the left side of the screen;
Toolbar=no whether the toolbar is displayed, yes for display;
Menubar,scrollbars represents the menu bar and scroll bar.
Resizable=no whether to allow changes to the window size, yes to allow;
Location=no whether the address bar is displayed, yes is allowed;
Status=no whether the information in the status bar is displayed (usually the file is open), yes to allow;
</SCRIPT> JS script End
  
"3, control pop-up window with function"
  
The following is a complete code.
<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 ")//written in one line
}
-->
</script>
<body onload= "Openwin ()" >
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 to call
it.
Method One: <body onload= "Openwin ()" > Browser pop-up window when reading the page;
Method Two: <body onunload= "Openwin ()" > Browser out of the page pop-up window;
Method Three: Call with a connection:
<a href= "#" onclick= "Openwin ()" > Open a Window </a>
Note: The "#" used is a virtual connection.
Method Four: Use a button to invoke:
<input type= "button" onclick= "Openwin ()" value= "open Window" >
 
"4, pop-up 2 windows at the same time"
  
Change the source code a little bit:
  
<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 ")//written in one line
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
into one line
}
-->
</script>
To avoid the 2 windows that pop up, use top and left to control the pop-up positions without overwriting each other. And I said it in the last
Four ways to call.
Note: The name of the 2 windows (NewWindows and NewWindow2) is not the same, or simply all empty.
"5, the main window to open the file 1.htm, while pop-up small Windows page.html"
The following code is added 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 of the timing off control"
  
Below we have some control of the pop-up window, the effect is better. If we add a small piece of code to the pop-up page (
Note that adding page.html to the HTML, not the main page, so that it automatically shuts down in 10 seconds is cooler.
First, add the following code to the <script language= "JavaScript" >
function Closeit ()
{
SetTimeout ("Self.close ()", 10000)//MS
}
</script>
Then, then use the <body onload= "Closeit ()" > This sentence to replace page.html Central some <BODY> this sentence on it. (
Don't forget to write this sentence. The function of this sentence is to call the code that closes the window, and then close the window itself after 10 seconds. )
"7, add a Close button in the pop-up window"
<FORM>
<input type= ' BUTTON ' value= ' ' close ' ' onclick= ' window.close () ' >
</FORM>
Oh, now more perfect.
"8, included pop-up window-one page two windows"
The example above contains two windows, one is the main window and the other is a pop-up window. In the following example, you can
Page to complete the above effect.
<script language= "JavaScript" >
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" >
</body>
Look at the code inside the OpenWindow.document.write () is not standard HTML. Just write more lines in the format.
。 Be sure to pay attention to one more label or one less label will cause errors. Remember to end with OpenWindow.document.close ().
"9, the Ultimate application-pop-up window of the cookie control"
Recall that the pop-up window above is cool, but there's a little bit of a problem, like you put the script above in a way that requires frequent
Page (for example, home), then each refresh this page, the window will pop up once, we use cookies to control it

First, add the following code to the <HEAD> area of the homepage 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"
}
}
</script>
Then, with <body onload= "Loadpopup ()" > (note not openwin but Loadpop ah.) Replace the main page in the central
<BODY> this sentence can be. You can try to refresh the page or re-enter the page, and the window will never pop again. Real pops.
-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.