How to use Javascript to search for XY coordinates in a browser?

I try to do this when the user scrolls down the page, clicks the link, does what they need to do, and then returns to the pages with links, they are the same (xy) in the browser they were before. How to do it?

I am new to the DOM, so I don’t know too much about how to do this.

Target browsers: IE6 / 7/8, Firefox 2/3, Opera, Safari

Added: I am using a program called jQuery to help me find out

+4
source share
5 answers

To get the xy location where the user clicked on the page, use the following jQuery code:

<html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> jQuery(document).ready(function(){ $("#special").click(function(e){ $('#status2').html(e.pageX +', '+ e.pageY); }); }); </script> </head> <body> <h2 id="status2"> 0, 0 </h2> <div style="width: 100px; height: 100px; background:#ccc;" id="special"> Click me anywhere! </div> </body> </html> 
+3
source

Try this or this .

0
source

As far as I remember, the code for obtaining a position in the viewport differs between browsers, so it would be easier to use some kind of structure, for example Prototype has a document.viewport.getScrollOffsets function (which, I believe, is the one you need).

However, obtaining coordinates is only one part, the other is to do something with them later. In this case, you can add the eventener event to the window.unload event, when it fired, save the location in a cookie, and then when the user opens the page again, check if this cookie is present and scroll accordingly.

Although, if everything you care about returns the user to the place where he was when he comes to the page via the "Back in the browser" button, do most browsers not do this automatically?

0
source

Typically, the browser saves the page view if you navigate and then back (try it on any pages of your favorite news site). The only exception is probably if you configure your cache settings to reload and re-process the page each time.

Not doing this (i.e. never setting your page to never cache) is probably the easiest and least intrusive way to solve your problem.

0
source

you can use offsetLeft and offsetTop

-1
source

Source: https://habr.com/ru/post/1276718/


All Articles