Javascript custom event firing

C

CJ

I have an issue with trying to create a custom event in javascript
that I need to capture in windows... Let me try explain how I need it
to work before I go asking questions!

I have a windows application called "TestShell" that has a WebBrowser
control on one of the forms. This application is actually written in
C#, but is irrevelant to what I'm trying to achieve. The WebBrowser
control is going to display a page with some javascript on it. What I
am trying to achieve, but cannot, is: get the java web page to fire a
custom event that my TestShell application can capture or listen to.
So it's a client side event I require, not one that posts or submits
back to the server. This event can be fired from a button click,
leaving a text box, and some other areas, and my windows application
needs to listen to and subscribe to this event.

I have solved the problem in a roundabout manner, but I am looking for
a neater solution if possible. What I have done is:
- Added a HTML button to the bottom of my page and made it invisible
(called 'btnFireMyEvent' in this example)
- Created a click event for this button (I left it blank because I
don't use it on the page)
- I fire this click event from my different required areas (button
click, leaving a text box, etc) by using something like the following
code:

var newEvent = document.createEventObject();
document.all('btnFireMyEvent').fireEvent("onclick", newEvt);
newEvent.cancelBubble = true;

- Now, in my C# application, I can find the button object through my
webbrowser control, and use AttachEventHandler on this button to
attach a function to it. What this does is runs my function in the C#
app when I see this button getting clicked... or in this case, the
click event just getting fired.

This keeps my events client side and allows me to do something outside
of my browser in response to an event.

In case you are wondering why I need to do this, it's to do with a
smart client application and the web page is going to be a legacy java
page that we need to communicate with. Unfortunately, the proposed
javascript on msdn doesn't work. That is why I have at to go down this
route.

This works fine, but is a little messier than I expected. I thought I
would be able to fire an independent event (like a windows event or
something) that I could either capture in my app or use my webbrowser
control to attach a function to it. The problem with the above
solution is that we will have to get the developers of the legacy page
to add a button for every event we want to fire. They are aware that
they must add a few things to the page to allow us to "hook" into it,
but I was hoping for less changes than this.

Any one have any ideas?

Thanks.
C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top