Loading ...
Sorry, an error occurred while loading the content.

Include onclick mouse coordinates in url

Expand Messages
  • chris.fishter
    In an svg object, lets say an image. When the user clicks on the image I would like to open a new window with the mouse coordinates in the link url. Something
    Message 1 of 2 , Mar 11, 2009
    • 0 Attachment
      In an svg object, lets say an image.
      When the user clicks on the image I would like to open a new window with the mouse coordinates in the link url.

      Something like (snippet):

      function relCoords(evt)
      {
      var newScale = SVGRoot.currentScale;
      var translation = SVGRoot.currentTranslate;
      pt.x = (evt.clientX - translation.x)/newScale;
      pt.y = (evt.clientY - translation.y)/newScale;
      open.Window(href='http://?x=' + pt.x + 'y=' + pt.y)

      };


      <image onclick="relCoords(evt)" src=....>


      Thanks in advance.

      Chris
    • Frank Bruder
      ... Looks mostly okay. There are some undefined variables, though. Better try: function relCoords(evt) { var rootElement = evt.target.ownerSVGElement; var
      Message 2 of 2 , Mar 25, 2009
      • 0 Attachment
        > In an svg object, lets say an image.
        > When the user clicks on the image I would like to open a new window with > the mouse coordinates in the link url.
        >
        > Something like (snippet):
        >
        > function relCoords(evt)
        > {
        > var newScale = SVGRoot.currentScal e;
        > var translation = SVGRoot.currentTran slate;
        > pt.x = (evt.clientX - translation. x)/newScale;
        > pt.y = (evt.clientY - translation. y)/newScale;
        > open.Window( href='http://?x=' + pt.x + 'y=' + pt.y)
        >
        > };
        >
        > <image onclick="relCoords( evt)" src=....>

        Looks mostly okay.
        There are some undefined variables, though.
        Better try:

        function relCoords(evt)
        {
        var rootElement = evt.target.ownerSVGElement;
        var newScale = rootElement.currentScale;
        var translation = rootElement.currentTranslate;
        var x = (evt.clientX - translation.x)/newScale;
        var y = (evt.clientY - translation.y)/newScale;
        window.open( "example.php?x=" + x + "\u0026y=" + y );
        }

        And the image should have an xlink:href attribute, not src, of course.
      Your message has been successfully submitted and would be delivered to recipients shortly.