Home arrow JavaScript arrow Page 2 - Start Working With Browser Windows in JavaScript
JAVASCRIPT

Start Working With Browser Windows in JavaScript


This series of articles mainly concentrates on working with browser windows and their sub-windows in JavaScript. You can reuse these scripts to inject into server side controls easily (especially in .NET and Java).

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 14
April 18, 2006
TABLE OF CONTENTS:
  1. · Start Working With Browser Windows in JavaScript
  2. · How to move the current browser window using JavaScript
  3. · How to maximize the current browser window using JavaScript
  4. · How to open a new pop up window using JavaScript
  5. · A word of caution

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Start Working With Browser Windows in JavaScript - How to move the current browser window using JavaScript
(Page 2 of 5 )

Now, let us try to develop a simple script (JavaScript) to move the current browser window.  Have a look at the following code:

<html>
      <head>
            <meta  name=vs_targetSchema
 content="http://schemas.microsoft.com/intellisense/ie5">
<script  id="clientEventHandlersJS"  language="javascript">
<!--
function Apply(x,y)
{
      window.moveTo(x,y); 
      //window.moveBy(x,y);
}

function ButtonMove_onclick() {
      var x = document.all("txtX").value;
      var y = document.all("txtY").value;
      Apply(x,y);
}
//-->
            </script>
      </head>
      <body>
            <form  id="form1">
                  Enter X:<input  type="text"  id="txtX"  NAME="txtX"
 value="100"><br>
                  Enter Y:<input  type="text"  id="txtY"  NAME="txtY"
 value="200"><br>
                  <input  type="button"  value="Show"  id="ButtonMove"
 name="ButtonMove"  onclick="return ButtonMove_onclick()">
            </form>
      </body>
</html>

Within the above code, I managed to create two textboxes named “txtX” and “txtY” and a button named “ButtonMove.”  When the button (buttonMove) is clicked, the control goes to the function “ButtonMove_onclick.”  This function mainly captures the values (X and Y) given by the user and finally calls another function, “Apply” (along with passing those values).

The function “Apply” mainly contains the following statement:

      window.moveTo(x,y);

The “window” is a built-in object in JavaScript which contains a method, “moveTo.”  The method accepts two parameters, left and top (or x and y).  The method automatically moves the window to the specified left and top values provided.  The above statement moves the current browser window (on which your web page is displayed) to the left and top values you specified within the textboxes.  Let us consider another alternative:

      window.moveBy(w,h); 

This is very similar to what I explained in the previous section.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials