Skip to main content
gamedev.net
🔒 Locked

[web] XUL\Javascript virtual function problem

Started by aidan_walsh Dec 18, 2005 at 4:31 PM 2 replies 1.5k views
Original Post
aidan_walsh
aidan_walsh
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?
www.aidanwalsh(.net)(.info)
markr
markr
Several ideas:

1. onclick is actually spelt onclick, not onClick, OnClick, or any other capitalisation. It's all lower case. &#106avascript is case sensitive.<br/><br/>2. You shouldn't be using the onclick property anyway, use the DOM events API, i.e. addEventListener (IIRC)<br/><br/>Perhaps the element no longer supports the deprecated onclick property (or even, the plain wrong onClick property)<br/><br/>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.<br/><br/>Mark
aidan_walsh
aidan_walsh
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. &#106avascript is case sensitive.<!--QUOTE--></td></tr></table></blockquote><!--/QUOTE--><!--ENDQUOTE--><br/>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]<br/><br/><!--QUOTE--><blockquote><span class="smallfont">Quote:</span><table border="0" cellpadding="4" cellspacing="0" width="95%"><tr><td class="quote"><!--/QUOTE--><!--STARTQUOTE--><i>Original post by markr</i><br/>2. You shouldn't be using the onclick property anyway, use the DOM events API, i.e. addEventListener (IIRC)<br/><br/>Perhaps the element no longer supports the deprecated onclick property (or even, the plain wrong onClick property)<br/><br/>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.<br/><br/>Mark<!--QUOTE--></td></tr></table></blockquote><!--/QUOTE--><!--ENDQUOTE--><br/>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.
www.aidanwalsh(.net)(.info)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.