...

View Full Version : mouse coordinates in title bar



alban
11-04-2005, 11:57 AM
hello

I once used a javascript that would display mouse coordinates in the browser's title bar yet it only worked with I.E 5.
Would anyone know of a similar script that would be cross/browser and cross-platform ?

Thanks in advance for any useful advice

regards

alban

Mr J
11-04-2005, 02:02 PM
Give this a try


<script type="text/javascript">
<!--
IE=document.all

if(document.layers){
document.captureEvents(Event.MOUSEMOVE)
}

function position(loc){

if(IE){
x=event.clientX
y=event.clientY
}
else{

if(document.layers){
x=loc.pageX
y=loc.pageY
}
else{
x=loc.pageX - document.body.scrollLeft // in relation to window
y=loc.pageY - document.body.scrollTop // in relation to window
}

}

document.title = x+" | "+y;

}
document.onmousemove = position;
// -->
</script>

Pyth007
11-04-2005, 02:18 PM
Actually, just to fix up the code a bit, change the document.title = x/y lines to:

document.title = x+" | ";
document.title += y;
so that both coordintes are displayed... Also note that in IE, it works "smoother" than in FF, probably because of the extra calculations that FF has to do...

alban
11-04-2005, 07:18 PM
Thanks to both of you but I'm stuck
It just doesn't work on my browsers (safari / firefox / opera) on OS X
Did I miss a thing ?

here's the script i used in the file body (worked on IE and Opera
with no OnLoad event handler
覧覧覧覧覧覧覧

<script language="javascript">
<!--
var where = ""; // which link
var isNav = (navigator.appName == "Netscape") ? true:false;
function checkwhere(e) {
if(isNav) {evt = e;}
else {evt = event;}
xCoord = window.evt.x;
yCoord = window.evt.y;
document.title = "customized title text : "+ xCoord + " | " + yCoord;
}


document.onmousemove = checkwhere;
if(isNav) {document.captureEvents(Event.MOUSEMOVE);}
//-->
</script>

覧覧覧覧覧

Any idea ?


Thanks in advance

regards

alban

Mr J
11-04-2005, 08:17 PM
pyth007
Thanks for the observation, a boo boo on my part:D


alban
Does the script I posted now work in those browsers?

I tried it in IE6, Mozilla, Firefox, and NS7

alban
11-05-2005, 12:53 PM
pyth007
Thanks for the observation, a boo boo on my part:D


alban
Does the script I posted now work in those browsers?

I tried it in IE6, Mozilla, Firefox, and NS7


hello

well it now works
thanks a lot and my apologies : invisible characters (in my text editor) had parsed the source code and made the javascript uneffective. Viewing the page's source in my browser made me notice theses characters and remove them.
So it works properly (firefox, opera, safari - IE 6 untested - doesn't exist for OS X) and i'm very glad.

Thanks a lot for the help

regards

alban



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum