Window Properties
1.The status Property
One of the most useful (and most abused) properties is the window’s status.
The value of this property defines what appears in the window’s status bar. One common status is the URL of a link you are mousing over.
You can use the status property to change what appears in the status bar. You may have noticed that some people put a kind of marquee in this area, scrolling across the bottom with messages like Buy our stuff! Buy our stuff! I don’t want to encourage status bar abuse, so I’m not going to teach you exactly how to do that, but you can use these JavaScript techniques to create a similar effect. To change what appears in the status bar of a window, use a <body> tag like this:
<body onLoad = "window.status = 'hi there!';">
This tag tells JavaScript to change the contents of the window’s status bar after the page has been fully loaded into the browser.
You might want to use the status property to inform visitors about the site they’ll see if they click a link. For example, if you have a link to a very graphics-intensive site, the words Warning: This site has a lot of graphics could appear in the status bar when the visitor mouses over the link. You can set this up with an onMouseOver:
<a href = "http://www.myheavygraphicsite.com/" onMouseOver =
"window.status='Warning: This site has a lot of graphics'; return true;">
My Heavy Graphic Site</a>
2. The opener PropertyThe opener Property
When one window opens a new window, the new window remembers its parent (the original window) using the opener property. An opened window can access its parent through this property and then manipulate the parent. For example, if you want a link in the new window to change the contents of the status bar in the original window, you’d include the following code inside a link in the new window:
<a href = "#" onClick = "var my_parent = window.opener; my_parent.status='howdy'; return false;">put howdy into the status bar of the original window</a>
The first statement inside the onClick says, “Find the window that opened me, and set the variable my_parent to point to that window.” The second statement changes the status property of that window to howdy.
Or you can make this simple
put howdy into the status bar of the original window
3. More Window Methods :
You’ve seen four window methods so far: open(), close(), focus(), and blur().
Let’s look at two more that come in handy from time to time: resizing and moving windows.
Resizing Windows
Modern browsers provide two different ways your JavaScript can resize a window. The window.resizeTo() method resizes a window to a given width and height. To change a small window into one that’s 500 pixels wide and 200 pixels high, you’d use the following script:
window.resizeTo(500,200);
Alternatively, you can change the size of a window by a specific amount using window.resizeBy(). The window.resizeBy() method takes two numbers: how much the width of the window should change and how much the height should change.
The code window.resizeBy(10, -5);makes a browser 10 pixels wider and 5 pixels shorter.
Moving Windows
The window.moveTo() method moves a window to an absolute position on the screen. If you want the window in the upper-left corner of the user’s screen, you’d type:
window.moveTo(0,0);
The first number is the number of pixels from the left border of the screen you want the window’s upper-left corner to appear, and the second number is the number of pixels from the top of the screen.
An alternative to window.moveTo() is window.moveBy(). If you want to move a window 5 pixels to the right and 10 pixels down from its current position, you’d type:
window.moveBy(5,10);
The first number is the number of pixels to the right you want to move the window, and the second is the number of pixels down. If you want to move the window 10 pixels up and 5 to the left, just use negative numbers:
window.moveBy(-5,-10);
Be careful not to move a window entirely off a user’s screen. To ensure
against this possibility, you have to know the size of the user’s screen. The two
properties that indicate this are:
window.screen.availHeight
window.screen.availWidth
TO calculate a particular point in a page we can use
var left_point = parseInt(width / 2) - parseInt(window_width / 2);
No comments:
Post a Comment