ImageViewer ActiveX Component and onClick() event bug / problems - onClick event being triggered by clicking anywhere? (Resolved: alert popup was the problem)

This problem is resolved. It seems the onClick function and using an alert on newer versions of IE will cause the problem described below.

-–

Hi there, I have a problem when trying to implement my own onClick event with the ImageViewer ActiveX Component. My ImageViewer ActiveX object is created in Javascript and appended to the DOM. Then, I call the following function to enable the call of the onClick event when the left mouse button is clicked on the ImageViewer.

imageViewer.SetOnClickEventStatus(true);

After that, I create a script to indicate which Javascript function to call when the ImageViewer onClick event is called.

var lScript = document.createElement(“script”);

lScript.type = “text/javascript”;

lScript.htmlFor = “imageViewer”;

lScript.event = “onClick()”;

lScript.appendChild(document.createTextNode(“onClick();”));

this.mContainer.appendChild(lScript);

function onClick()

{

alert(‘Hi!’); // Just a test to see if the function is being fired.

}

Something interesting then happens. Once the camera feed is being displayed, if I click on the ImageViewer component, the alert popup is being displayed. Great! However, after I close the popup, If I click anywhere else (and I mean anywhere, even on the IDE on my other monitor) or anywhere else on the page, the function is being fired again and the alert message keep popping up, even if I am not clicking on the ImageViewer component anymore.

The first time works as intended. If I open the page, let the component load and click anywhere, it won’t do anything. But as soon as I click the component and the function gets called, then any click, anywhere, will call the function again.

Any idea why this might be happening?

We reproduced this behavior, but after testing a bit it turns out that it does not seem to be a problem with the ActiveX as such, but rather something with the alert() function in IE. I tried changing the onClick method to update a text on the web page instead of showing the alert and then the click behavior ‘stayed on’ the ActiveX. Clicking on the ActiveX would keep updating the text, while clicking outside it does nothing.

So for some reason opening the alert makes IE start passing all click events on to the ActiveX. This is rather new behavior as we have not experienced it with older versions of IE, and to be honest I don’t think we can do much about it from our side.

I hope this information makes it possible for you to get on with your project.

Thank you for coming back to me Peter. You are right, I changed the function to log messages and append text to the page and it seems to be working fine. The alert was only for testing purposes and I do not need it for the project I am working on. I am glad to see it is working as intended. Have a great day!