JavaScript Tutorial/Window/open — различия между версиями
(нет различий)
|
Версия 21:52, 25 мая 2010
Содержание
- 1 Open new window
- 2 Open new window with "_blank" setting
- 3 Open new window with "toolbar=no, status=no, width=200,height=200"
- 4 Open window in different styles
- 5 Popup window with window.open
- 6 This example pops up a new window and then writes a string to it
- 7 Using document.write() on Another Window
- 8 This document is brand new.
- 9 This document is brand new.
Open new window
<source lang="javascript">
<HTML> <HEAD> <SCRIPT language="JavaScript">
</SCRIPT> </HEAD> <BODY> <FORM name="myform"> <INPUT TYPE="button" value="Open New Window" onClick="new_win()"> </FORM> </BODY> </HTML></source>
Open new window with "_blank" setting
<source lang="javascript">
<html> <head> <script language="JavaScript" type = "text/javascript">
</script> </head> <body> <input type="button" value="Click Button" onClick="GreetingWin()"> </body> </html></source>
Open new window with "toolbar=no, status=no, width=200,height=200"
<source lang="javascript">
<html> <head> <script language="JavaScript" type = "text/javascript">
</script> </head> <body> <input type="button" value="Click Button" onClick="GreetingWin()"> </body> </html></source>
Open window in different styles
<source lang="javascript">
<html> <head> <title>Open Window</title> <script language="JavaScript" type =" text/javascript">
</script> </head> <body> <form name="form1">
<input type="checkbox" name="directories" value="0">Directories Option</p>
<input type="checkbox" name="location" value="0">Location Option
<input type="checkbox" name="menubar" value="0">Menu Bar
<input type="checkbox" name="resized" value="0">Allow Window to be Resized
<input type="checkbox" name="scrollbars" value="0">Scrollbars
<input type="checkbox" name="status" value="0">Status Bar
<input type="checkbox" name="toolbar" value="0">Toolbar
<input type="button" value="Create Window" name="CreateWin" onClick="ChangeLink(this.form)">
</form> </body> </html></source>
Popup window with window.open
<source lang="javascript">
<html> <head> <script language="JavaScript" type = "text/javascript">
</script> </head> <body> <input type="button" value="Click Button" onClick="GreetingWin()"> </body> </html></source>
This example pops up a new window and then writes a string to it
<source lang="javascript">
<html> <head> <title>Document Open/Close Example</title> </head> <body>
Due to new popup blockers, this code can only run when you click the following button:
<input type="button" value="Click Me" onclick="showPopup()" /> <script type="text/javascript"> function showPopup() { var oNewWin = window.open("about:blank", "newwindow", "height=150,width=300,top=10,left=10,resizable=yes"); oNewWin.document.open(); oNewWin.document.write("<html><head><title>New Window</title></head>"); oNewWin.document.write("<body>This is a new window!</body></html>"); oNewWin.document.close(); } </script> </body> </html></source>
Using document.write() on Another Window
<source lang="javascript">
<html> <head> <title>Writing to Subwindow</title> <script type="text/javascript"> var newWindow; function makeNewWindow() {
newWindow = window.open("","","status,height=200,width=300");
} function subWrite() {
if (newWindow.closed) { makeNewWindow(); } newWindow.focus(); var newContent = "<html><head><title>title</title></head>";newContent += "<body bgcolor="coral">
This document is brand new.
";newContent += "</body></html>"; newWindow.document.write(newContent); newWindow.document.close();
} </script> </head> <body onload="makeNewWindow()"> <form> <input type="button" value="Write to Subwindow" onclick="subWrite()"> </form> </body> </html></source>
Using document.write() on the Current Window
<source lang="javascript">
<html> <head> <title>Writing to Same Doc</title> <script type="text/javascript"> function reWrite() {
var newContent = "<html><head><title>title</title></head>";newContent += "<body bgcolor="aqua">
This document is brand new.
";newContent += "Click the Back button to see original document."; newContent += "</body></html>"; document.write(newContent); document.close();
} </script> </head> <body> <form> <input type="button" value="Replace Content" onclick="reWrite()"> </form> </body>
</html></source>