Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question mouse coordinates in title bar

    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

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Give this a try

    PHP Code:
    <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> 
    Last edited by Mr J; 11-04-2005 at 09:12 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, just to fix up the code a bit, change the document.title = x/y lines to:
    Code:
    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...

  • #4
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    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

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    pyth007
    Thanks for the observation, a boo boo on my part


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

    I tried it in IE6, Mozilla, Firefox, and NS7
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #6
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Fixed!

    Quote Originally Posted by Mr J
    pyth007
    Thanks for the observation, a boo boo on my part


    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •