Solved

How to show the current x,y coordinate?

Posted on 2001-06-15
6
266 Views
Last Modified: 2006-11-17
I would like to get the xy coordinate of the current screen relative to the whole page.....how can i do that?
Actually I need this because I want to do a floating frame which will follow the screen as you scroll.  So what I am gonna do is get teh xy coordinate of the current screen.....and then set the iframe to the position.  Are there any other way that I don't need to get the xy coordinate of the current screen? Just like I can set the position relative to the current screen?
Plz help....thx
0
Comment
Question by:armansiu
  • 4
  • 2
6 Comments
 
LVL 9

Accepted Solution

by:
nimaig earned 200 total points
ID: 6195622
Check this


<html>
<head>
<script language="javascript">
<!--
     function getXY(){
          if (window.pageXOffset > -1) {
             x = window.pageXOffset;
             y = window.pageYOffset;
         } else if (document.body) {
             x = window.document.body.scrollLeft;
             y = window.document.body.scrollTop;
         }
         alert("x :" + x)
         alert("y :" + y)
     }
//-->
</script>  

</head>
<body leftmargin=5 topmargin=0>
<form>
Hello .......... testing ............
<input type="button" value=" Click " onClick="getXY()">
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<input type="button" value=" Click " onClick="getXY()">
<table width="200%">
<tr><td align="right" width="200%"><input type="button" value=" Click " onClick="getXY()"></td></tr>
</table>

</form>
</body>
</html>
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6195638
You can get similar example. It is of floating logo. You can modify as per your requirement :

http://www.dynamicdrive.com/dynamicindex4/logo.htm
0
 

Author Comment

by:armansiu
ID: 6195683
but why we need that if statement?
and what's the difference between scrollLeft and pageXOffset?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:nimaig
ID: 6195707
That is to make it work in Netscape
0
 
LVL 9

Expert Comment

by:nimaig
ID: 6195711
That is to make it work in Netscape
0
 

Author Comment

by:armansiu
ID: 6195720
Thanks so much =)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question