2

I have a COM object that raises events and JavaScript on the web page to capture those events. It all works perfectly. Now I have to "distribute" this JavaScript to several other web applications for use on their web pages (this is all internal intranet stuff).

Here is the JavaScript function and script tag for the event sink:

<script for="ica" event="OnAgentEvents(evd)" language="javascript">
    function ica::OnAgentEvents(evd) {
        // do stuff here
    }
</script>

How can I put this into a separate .js file? Or does it have to remain on the page itself?

The ica object is on the page in an object tag:

<object classid="clsid:55527FAD-5E60-4F44-867B-9F6E7B0DB9DD" id="ica" name="ica"></object>
2
  • I have a similar object, whilst I haven't put the javascript in a separate file (yet), I also figured out that you don't need any of the attributes in the <script> tag - I have a plain <script> tag with multiple obj::event style handlers within it, leading me to think that they will be fine in a separate file. Commented Mar 17, 2015 at 17:11
  • Use either <script for= event= > with the actual code directly inside the <script> tag, or function objectName::eventName. Those are two different, independent mechanisms to achieve the same effect, they aren't supposed to be combined the way you try to. Commented Mar 18, 2015 at 2:05

1 Answer 1

2

Regarding my comment, I just tried it and it works fine. When working with embedded COM objects in this fashion, I found out that you don't need to specify the for and event attributes on the <script> tag. In our case, we have a single <script> tag that has 3 different event handlers of the form objectID::Eventname within them.

Since it was onhand, I've just moved the contents of this script tag to a separate js file and referenced it as normal - everything still functions as it should.

Sign up to request clarification or add additional context in comments.

3 Comments

but how would I translate the javascript to jquery?
@danhenderson I'm not sure what you mean - this isn't in the realms of jQuery, it's all pure JavaScript. Once you're within your JavaScript event handler, you're free to do as you wish, including using jQuery functionality.
thanks for the information. this will get me going.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.