Events rewritten in ASP.AJAX on IE7

Hello!

I am calling a web service from Javascript when a user clicks on a link. I need to get the coordinates that the user has clicked on so that I can display the DIV at the appropriate location. My client side script looks like this:

var g_event;

function DoWork(event, theId) 
{
    if (IsIE())
       g_event = window.event;
    else
        g_event = event;

    Acme.WebServices.Worker.GetInformation(theId, DoWorkSuccess);
}

function DoWorkSuccess(result) 
{
    var l_elemDiv = document.getElementById("content-area-div");
    DisplayAreaDiv(g_event, l_elemDiv, result);
}

      

It is used as follows:

<a href="" onclick="DoWork(event, "help");">Help</a>

      

This works great in Firefox, Safari and Opera. There isn't much in IE7. For example, if I put the following code at the end of the DoWork () and DoWorkSuccess () functions:

alert(g_event.clientX + ", " + g_event.clientY);  

      

In IE, I get two warnings; the first has the correct coordinates, and the second (which is displayed on top of the first) is just "[object]". Since this "[object]" one is the last one, my DIV does not display correctly in the upper left corner of the browser window. Is there a way I can prevent IE from giving me a second "bad" event? Thank.

0


source to share


2 answers


Why not retrieve and store the coordinates in DoWork and just use them in DoWorkSuccess instead of storing the event. Of course, this won't work if there is more data you are pulling from the event.



var client_x;
var client_y;

function DoWork(event, theId) 
{
    var g_event;
    if (IsIE())
       g_event = window.event;
    else
        g_event = event;

    client_x = g_event.clientX;
    client_y = g_event.clientY;

    Acme.WebServices.Worker.GetInformation(theId, DoWorkSuccess);
}

function DoWorkSuccess(result) 
{
    var l_elemDiv = document.getElementById("content-area-div");
    DisplayAreaDiv( { clientX : client_x, clientY : client_y }, l_elemDiv, result);
}

      

+1


source


Have you tried setting window.event.cancelBubble = true

in your DoWork function?



If not, quirks mode has a good article on events and event bubbles - http://www.quirksmode.org/js/events_order.html , which helped me a lot with this questions.

0


source







All Articles