JavaScript DHTML/Javascript Objects/window
Содержание
- 1 Add Desktop Component
- 2 Clear Interval
- 3 Clear Timeout
- 4 Close a window
- 5 Create a Popup window
- 6 Create a prompt
- 7 Define dialog arguments
- 8 Display an alert dialog
- 9 Display confirm dialog
- 10 Display information in status (window.status)
- 11 Execute Javascript
- 12 Handling Status Message Changes
- 13 Hide a window
- 14 Is window closed
- 15 Is window Open
- 16 Let window navigate to a URL (window.navigate("http://www.java2s.com"))
- 17 Move window By
- 18 Move window to
- 19 Navigate window to a URL
- 20 "offScreenBuffering" Example
- 21 Open a new Window
- 22 Open a new window and close it
- 23 Print a window
- 24 "screenTop" Example
- 25 Set Default Status Information
- 26 Set dialog window top
- 27 Set dialog window width
- 28 Set the dialog window height
- 29 Set the dialog window left
- 30 Set Timeout (window.setTimeout)
- 31 Show a Popup
- 32 Show Browser UI
- 33 Show Help (window.showHelp("URL"))
- 34 Show Modal Dialog (window.showModalDialog("URL", myArguments, ""))
- 35 Show Modeless Dialog (window.showModelessDialog(..))
- 36 Windown screen Left
- 37 Window resize By
- 38 Window self
Add Desktop Component
<source lang="html4strict">
<html> <head> <script language="JavaScript">
function function1() { window.external.AddDesktopComponent("http://www.wbex.ru/style/logo.png", "image", 150, 150, 95, 95); }
</script> </head> <body> <button onclick="function1();">Click here to add the new active desktop component </button> </body> </html>
</source>
Clear Interval
<source lang="html4strict">
<html> <body> <script language="javascript">
var intInterval = 0 function myInterval(){ alert("Hello"); }
</script> <button onclick="intInterval=window.setInterval("myInterval()", 1000);"> Start interval </button> <button onclick="intInterval=window.clearInterval(intInterval);"> Stop interval </button> </body> </html>
</source>
Clear Timeout
<source lang="html4strict">
<html> <body> <script language="javascript">
var intValue = 0 function myMethod(){ alert("Hello"); }
</script> <button onclick="intValue=window.setTimeout("myMethod()", 1000);">Start timeout</button> <button onclick="intValue=window.clearTimeout(intValue);">Stop timeout</button> </body> </html>
</source>
Close a window
<source lang="html4strict">
<html> <body> <button onclick="window.close();">Close window</button> </body> </html>
</source>
Create a Popup window
<source lang="html4strict">
<html> <body> <script language="JavaScript">
var popup = window.createPopup(); popup.document.body.innerHTML = "This will navigate to another site!"; popup.document.body.style.backgroundColor = "yellow";
</script> <input type="button"
onClick="location.href="http://www.wbex.ru";" onmouseover="popup.show(100, 100, 200, 100, document.body);" onmouseout="popup.hide();" value="Navigate to Another Site">
</body> </html>
</source>
Create a prompt
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
window.prompt("Please, enter your full name", "Yes, here");
} </script> <input type="button" value="Open a prompt window" onclick="function1();"> </body> </html>
</source>
Define dialog arguments
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
var myArguments = new Object(); myArguments.param1 = document.all.myColor.value; window.showModalDialog("http://www.wbex.ru", myArguments, "");
} </script> <select id="myColor"> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> <option value="yellow">Yellow</option> </select> <button onclick="function1();">Open Window</button> </body> </html>
</source>
Display an alert dialog
<source lang="html4strict">
<html> <body> <input type="button" onClick="alert("This is an alert window");" value="Click me"> </body> </html>
</source>
Display confirm dialog
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.confirm("Confirmation window"); }
</script> <input type="button" value="Click to bring up a confirm window" onclick="function1();"> </body> </html>
</source>
Display information in status (window.status)
<source lang="html4strict">
<html> <head> <script language="JavaScript">
function function1() { window.status = "Welcome to www.wbex.ru"; }
</script> </head> <body>
Check the status bar message.
</body> </html>
</source>
Execute Javascript
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
var m = window.execScript("alert("test");", "JavaScript"); alert("The method returns always "+"""+m+""");
} </script> <input type="button" value="Click to execute the script" onclick="function1();"> </body> </html>
</source>
Handling Status Message Changes
<source lang="html4strict">
<html> <head> <title>Generalizable window.status Property</title> <script type="text/javascript"> function showStatus(msg) {
window.status = msg; return true;
} </script>
</head> <body> <a href="http://www.example.ru"
onmouseover="return showStatus("Go to my Home page.")" onmouseout="return showStatus("")">Home</a>
<a href="http://mozilla.org" onmouseover="return showStatus("Visit Mozilla Home page.")" onmouseout="return showStatus("")">Mozilla</a>
</body> </html>
</source>
Hide a window
<source lang="html4strict">
<html> <body> <script language="JavaScript"> var myPopup function function1() {
myPopup = window.createPopup(); myPopup.document.body.style.backgroundColor = "yellow"; myPopup.show(100,100,100,200,document.body);
} </script> <input type="button" value="Show popup window" onclick="function1();"> <input type="button" value="Hide popup window" onclick="myPopup.hide();"> </body> </html>
</source>
Is window closed
<source lang="html4strict">
<html> <body> <button onclick="alert(window.closed);">closed Property Value</button> </body> </html>
</source>
Is window Open
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
var m = window.createPopup(); var n = m.document.body; n.style.border="solid 2px black"; n.innerHTML = "This is the pop-up window content"; m.show(350, 270, 200, 50, document.body); if (m.isOpen == true) { setTimeout("function2()", 2000); }
} function function2() {
alert("The pop-up window is Open");
} </script> <input type="button" value="Open pop-up window" onclick="function1();"> </body> </html>
</source>
<source lang="html4strict">
<html> <body> <button onclick="window.navigate("http://www.wbex.ru");">Go to www.wbex.ru page</ button> </body> </html>
</source>
Move window By
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.moveBy(100,100); }
</script> <input type="button"
value="Move the window 100 pixels to the left and 100 pixels" onclick="function1();">
</body> </html>
</source>
Move window to
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
window.moveTo(100,300);
} </script> <input type="button" value="Move window" onclick="function1();"> </body> </html>
</source>
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.navigate("http://www.wbex.ru"); }
</script> <input id=myB
type="button" value="Navigate to wbex.ru home page" onclick="function1();">
</body> </html>
</source>
"offScreenBuffering" Example
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.offScreenBuffering = false; var m = window.offScreenBuffering; alert("The value of offScreenBuffering for this window is: \n"+m); }
</script> <input type="Button"
value="Turn "off" the offScreenBuffering of this window" onClick="function1();">
</body> </html>
</source>
Open a new Window
<source lang="html4strict">
<html> <body> <input type="button"
value="Open a new window" onClick="window.open("http://www.wbex.ru", "_blank")">
<input type="button"
value="Open a blank document" onClick="document.open("test.htm", "_blank")">
</body> </html>
</source>
Open a new window and close it
<source lang="html4strict">
<html> <body> <script language="JavaScript">
var newWin function function1() { newWin = window.open("http://www.wbex.ru", "subwindow", "width=400,height=150, left=200, resizable, top=250") } function hi() { if (!newWin.closed) { alert("The subwindow is closed"); } }
</script>
Click to open new window
</body> </html>
</source>
Print a window
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.print(); }
</script> <input type="button" value="Print this window" onclick="function1();"> </body> </html>
</source>
"screenTop" Example
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
var m = "" m = "The left coordinate is: " + window.screenLeft + "\n"; m += "The top coordinate is: " + window.screenTop + "\n"; alert(m);
} </script> <body bottommargin="150"> <input type="button" value="Extract the coordinates" onclick="function1();"> </body> </html>
</source>
Set Default Status Information
<source lang="html4strict">
<html> <body> <body bottommargin=150"
onLoad="window.defaultStatus="This is the status bar message"">
</body> </html>
</source>
Set dialog window top
<source lang="html4strict">
<html> <body> <SCRIPT> function function1() {
event.srcElement.blur(); window.showModalDialog("http://www.wbex.ru", "", "dialogWidth:5cm; dialogHeight:10cm; dialogTop:0cm; dialogLeft:0cm")
} </SCRIPT> </HEAD> <BODY> <SELECT onchange="function1()">
<OPTION>Item 1</OPTION> <OPTION>Item 2</OPTION> <OPTION>Item 3</OPTION>
</SELECT> </body> </html>
</source>
Set dialog window width
<source lang="html4strict">
<html> <body> <SCRIPT> function function1() {
event.srcElement.blur(); window.showModalDialog("http://www.wbex.ru", "", "dialogWidth:5cm; dialogHeight:10cm")
} </SCRIPT> </HEAD> <BODY> <SELECT onchange="function1()">
<OPTION>Item 1</OPTION> <OPTION>Item 2</OPTION> <OPTION>Item 3</OPTION>
</SELECT> </body> </html>
</source>
Set the dialog window height
<source lang="html4strict">
<html> <body> <SCRIPT> function function1() {
event.srcElement.blur(); window.showModalDialog("http://www.wbex.ru", "", "dialogWidth:5cm; dialogHeight:10cm")
} </SCRIPT> </HEAD> <BODY> <SELECT onchange="function1()">
<OPTION>Item 1</OPTION> <OPTION>Item 2</OPTION> <OPTION>Item 3</OPTION>
</SELECT> </body> </html>
</source>
Set the dialog window left
<source lang="html4strict">
<html> <body> <SCRIPT> function function1() {
event.srcElement.blur(); window.showModalDialog("http://www.wbex.ru", "", "dialogWidth:5cm; dialogHeight:10cm; dialogTop:0cm; dialogLeft:0cm")
} </SCRIPT> </HEAD> <BODY> <SELECT onchange="function1()">
<OPTION>Item 1</OPTION> <OPTION>Item 2</OPTION> <OPTION>Item 3</OPTION>
</SELECT> </body> </html>
</source>
Set Timeout (window.setTimeout)
<source lang="html4strict">
<html> <body> <script language="javascript">
var intValue = 0 function myMethod(){ alert("Hello"); }
</script> <button onclick="intValue=window.setTimeout("myMethod()", 1000);">Start timeout</button> <button onclick="intValue=window.clearTimeout(intValue);">Stop timeout</button> </body> </html>
</source>
Show a Popup
<source lang="html4strict">
<html> <body> <script language="JavaScript"> var myPopup function function1() {
myPopup = window.createPopup(); myPopup.document.body.style.backgroundColor = "yellow"; myPopup.show(100,100,100,200,document.body);
} </script> <input type="button" value="Show popup window" onclick="function1();"> <input type="button" value="Hide popup window" onclick="myPopup.hide();"> </body> </html>
</source>
Show Browser UI
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.external.ShowBrowserUI("LanguageDialog", null); } function function2() { window.external.ShowBrowserUI("OrganizeFavorites", null); } function function3() { window.external.ShowBrowserUI("PrivacySettings", null); }
</script> <input type="button"
value="Open the Language Preferences dialog box." onclick="function1();">
<input type="button"
value="Open the Organize Favorites dialog box." onclick="function2();">
<input type="button"
value="Open the Privacy Preferences dialog box." onclick="function3();">
</body> </html>
</source>
Show Help (window.showHelp("URL"))
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1() { window.showHelp("http://www.wbex.ru"); }
</script> <input type="button" value="Open the help document" onclick="function1();"> </body> </html>
</source>
Show Modal Dialog (window.showModalDialog("URL", myArguments, ""))
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function openWindow() {
var myArguments = new Object(); myArguments.param1 = document.all.myColor.value; window.showModalDialog("http://www.wbex.ru", myArguments, "");
} </script> <select id="myColor">
<option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> <option value="yellow">Yellow</option>
</select> <button onclick="openWindow();">Open window</button> </body> </html>
</source>
Show Modeless Dialog (window.showModelessDialog(..))
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function openWindow() {
var myArguments = new Object(); myArguments.param1 = document.all.myColor.value; window.showModelessDialog("http://www.wbex.ru", myArguments, "");
} </script> <select id="myColor">
<option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> <option value="yellow">Yellow</option>
</select> <button onclick="openWindow();">Open window</button> </body> </html>
</source>
Windown screen Left
<source lang="html4strict">
<html> <body> <script language="JavaScript"> function function1() {
var m = "" m = "The left coordinate is: " + window.screenLeft + "\n"; m += "The top coordinate is: " + window.screenTop + "\n"; alert(m);
} </script> <body bottommargin="150"> <input type="button" value="Extract the coordinates" onclick="function1();"> </body> </html>
</source>
Window resize By
<source lang="html4strict">
<html> <body> <script language="JavaScript">
function function1(){ window.resizeBy(-100,-100); }
</script> <input type="button" value="Resize this window by (-100,-100)" onClick="function1();"> </body> </html>
</source>
Window self
<source lang="html4strict">
<html> <body id="myBody" bottommargin=150> <script language="JavaScript">
function function1() { alert(window.self.myBody.bottomMargin); }
</script> <input type="button" value="Bottom Margin" onclick="function1();"> </body> </html>
</source>