Sign in to follow this  

[web] XUL\Javascript virtual function problem

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to port someone else's extension over to FF1.5. My code is like this:
function foo(x, y, z){ }
function bar(){ var alice = window._content.document.createElement("a"); alice.onClick = function() { foo(x, y, z); return false; }; }

When I run this it gets as far as alice.onClick and then throws a "Component is not available" exception. I suspect that this is to do with XPCNativeWrappers for the extension, but I have no idea how to get around it so that I can use the virtual function. I have Googled, but I can't find anything that lets me know what the default names for XPCNativeWrappers created by FF might be. Or does anyone have a suggestion on how I can get around this another way?

Share this post


Link to post
Share on other sites
Several ideas:

1. onclick is actually spelt onclick, not onClick, OnClick, or any other capitalisation. It's all lower case. javascript is case sensitive.

2. You shouldn't be using the onclick property anyway, use the DOM events API, i.e. addEventListener (IIRC)

Perhaps the element no longer supports the deprecated onclick property (or even, the plain wrong onClick property)

onclick is a legacy method for adding event handlers and shouldn't be used. The reason is simple - you can't add more than one event handler for the same event using this method.

Mark

Share this post


Link to post
Share on other sites
Quote:
Original post by markr
Several ideas:

1. onclick is actually spelt onclick, not onClick, OnClick, or any other capitalisation. It's all lower case. javascript is case sensitive.

My bad, thats a typo in the example, but is correct in the code. Its a Java carryover I've had beaten into me at school, having the consecutive words in methods capitalised. [embarrass]

Quote:
Original post by markr
2. You shouldn't be using the onclick property anyway, use the DOM events API, i.e. addEventListener (IIRC)

Perhaps the element no longer supports the deprecated onclick property (or even, the plain wrong onClick property)

onclick is a legacy method for adding event handlers and shouldn't be used. The reason is simple - you can't add more than one event handler for the same event using this method.

Mark

Thats worth looking into. Actually, I hadn't considered that at all (I've only just started XUL, and any prior experience with JS has been little scripts every now and then.) Thanks.

Share this post


Link to post
Share on other sites

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this