Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does screenTop do?

Status
Not open for further replies.

Pichdude

Programmer
Aug 24, 2005
66
0
0
SE
Hi, I am using this script to capture the event when a user shuts down the webbrowser window using the "X". But is there anyone that can explain what "screenTop" actually do that makes this work?

Regards

Pichdude
 
In Internet Explorer screenTop is used to determine the x and y coordinates of the windows position in relation to the users monitor screen. It has nothing to do with the closing of the screen and it is an IE only property.



It's hard to think outside the box when I'm trapped in a cubicle.
In an increasingly self-focused society it is important to recognize the unselfish actions of others so they will feel encouraged to continue such actions. Please give acknowledgement to those who aid you whether it is waving to the person who let you out in traffic, tha
 
Stupid me forgot to post the link to the script I found using screenTop.


The reason I use it is that I only want to run onunload when the user closes the browser with the "X", not the close-button I also have on the page.

What I was wondering is what screenTop actually does in this case, it works great and I am just curious.

Regards

Pichdude
 
I made a little mistake in my first post. screenLeft is the property for the x coordinate while screenTop is the property for the y coordinate. I stated it as if screenTop did both.

screenTop in the link you show above returns the number of pixels from the top of the monitor display screen the content window of the IE page starts.
For instance, if my IE window is flush with the top of my monitor display screenTop reports a value of 128, meaning there are 128 pixels between the top of the monitor display and where the content window begins. The space in between is taken up by the top of the IE browser window and the toolbars. If I move the window down from the top edge of the monitor display the value of screenTop increases by the same number of pixels.

In the case of a line like this:
< body onunload = "if (screenTop > 9999) alert('Closing');">
When the page begins to unload the code says:
If the content window starts at more than 9999 pixels from the top of the screen then send an alert.

Realistically, your content window will not be that far down the screen as your monitor is not going to display that many pixels anyway. Most likely the person using this code was setting his window position to be way below the actual displayable screen. Probably the window was not meant to be visible but to remain open for other reasons and when the page is closed it tests if the page is in it's off-screen position and sends the alert.

For your use you do not need the if statment, just use something like:
<body onunload="alert('closing');">

Again, the screenTop property is an IE only property. Using it with other browsers will not get you the same results because screenTop would not have a value so the if statement would not evaluate and trigger the alert.



It's hard to think outside the box when I'm trapped in a cubicle.
In an increasingly self-focused society it is important to recognize the unselfish actions of others so they will feel encouraged to continue such actions. Please give acknowledgement to those who aid you whether it is waving to the person who let you out in traffic, tha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top