Get window position in js

This is something I’ve been trying to do for a while now and I feel silly for not getting it working. I’m sure it should be possible.

I want to find the position on the users screen of a popup window. I know I can position one where I want, but say the user then moves it, can I then get X-Y coordinates so I can know where the user has moved it? I can get the width and height without issue…

Yes you can but it involves checking which browser is being used!
IE understands screenLeft and screenTop but not screenX and screenY which everything else does.

so this should work cross browser!

      <script type="text/javascript">

function whereisit () {
	if (navigator.appName.indexOf("Netscape")!=-1
		&&parseInt(navigator.appVersion)>=5) {
	     x = "Value of Left coordinate is: " + window.screenX;
         y = "Value of Top coordinate is: " +  window.screenY;
	else if (navigator.appName.indexOf("Microsoft")!= -1 
	  &&parseInt(navigator.appVersion)>=4) {
	     x = "Value of Left coordinate is: " + window.screenLeft;
         y = "Value of Top coordinate is: " +  window.screenTop;

       <input type="button" onclick="whereisit()"  value="Coordinate Value">


Ahh huge thanks for that, that seems to work brilliantly! :smiley:

No problem, glad I could help! Javascript isn’t my strongest point but I am getting there!