Jump to content
  • Advertisement
Sign in to follow this  
aidan_walsh

[web] XUL\Javascript virtual function problem

This topic is 4689 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!