Trap JS events within an Object Tag

Posted on 2003-11-04
Last Modified: 2012-06-27
Hello, I have a html like this

<object id="UploadControl" width="100%" height="100%" classid="clsid:1E2941E3-8E63-11D4-9D5A-00902742D6E0" codebase="<<some .cab file>> Version=5,0,3,0">
<param name="SampeName" value="1">
<<... other params come here>>

This tag is primarily used in a mail application to display attachments in that mail. When a user double-clicks on one of the attachments, I want to be able to trap that event and display a custom alert. Currently, the attachment opens up using it's respective application. I am not able to prevent it from going to the application and instead display a custom message. I have tried giving 'onLoad' events on the object tag, a div tag that encloses it, on the body tag. Also tried this

<script language=javascript for="UploadControl" event="onfocus">
alert('handler comes here');

but all in vain. Could someone please help me with idea(s) to trap the javascript events on an Object tag with code base for an ActiveX control?
Question by:shyam619
  • 4
  • 2
LVL 10

Expert Comment

ID: 9684577
hi there.

i havent tried it with object but you can do the following:

<div onclick="alert('....')">
  <object .... >

now when the user clicks on something inside the object it should trap the mouse event.
there can be some exceptions:

whne you click on a button the button i dont know the sequesnce
it will execute the onclick.

another solution (not recommanded) is to capture mouse event
in the document and then see if the source is the object.

document.onclick = new function(){
                                                         if ( get Source based on browser == object element)  


LVL 10

Expert Comment

ID: 9684584
the problem is that object is a seperate application so my guess that
the solution i gave you above will not work, but you still can give it a shot.

Author Comment

ID: 9684603
Thanks Nushi. I have already tried the div tag approach. It is not working. Anything on the div, it displays the alert alright. But inside the object tag even though it is part of the div too, it fails to catch the event.
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 9684616
Also, I have a script like this to find out the source of the event. This does not work either.


function click()
alert('entered function for click');
  if(event.button == 0)
  return false;

document.getElementById('div name here').ondblclick=click;
LVL 10

Accepted Solution

Nushi earned 200 total points
ID: 9684995
Thats what i thought.
Object is an ActiveX which is independed.

what im tring to say is that Object doesnt have option to capture event unless
its part of the control.
whenever object is located inside the HTML its "capture" its own space
in which user/code can't get to it.

as far as i know there isnt any solution.

LVL 10

Expert Comment

ID: 9686101
LVL 16

Expert Comment

ID: 10352735
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: Nushi {http:#9686101}

Please leave any comments here within the next four days.

EE Cleanup Volunteer

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question