JavaScript DHTML/Javascript Objects/window

Материал из Web эксперт
Перейти к: навигация, поиск

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>
   
  


Let window navigate to a URL (window.navigate("http://www.java2s.com"))

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


Navigate window to a URL

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