Let'开发者_Go百科s get directly to the problem :
I'm actually doing a firefox extension in which i would like to implement the jWebsocket API in order to build a small chat. I got my main script file, named test.js, and the jWebsocket lib into a js folder. Just for you to know, this is my first firefox extension ever.
So in my XUL file I got this (for the script part only of course, the interface code is not shown) :
<overlay id="test-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://test/content/test.js" />
<script type="application/x-javascript" src="chrome://test/content/js/jwebsocket.js" />
jwebsocket.js being the file I need to call according to jWebsocket website.
In my main script file test.js I start with :
if (jws.browserSupportsWebSockets())
{
jWebSocketClient = new jws.jWebSocketJSONClient();
}
else
{
var lMsg = jws.MSG_WS_NOT_SUPPORTED;
alert(lMsg);
}
jws being the namespace created into the jwebsocket.js file.
Of course I've got the required stand-alone server running in background, and working.
So from what I understood looking on various websites, is that if a js file is loaded into the javascript allocated memory space (with the tag), all namespace/function should be available between each file. But this was mostly for HTML-oriented issues, so I'm not sure if it applies to XUL/Firefox environment.
But the script keep failing at the first jws call.
Any ideas on what goes wrong here ? I'm stuck for 2 days now :/
Yes, is the same of HTML developing, you have your namespace avaiable between each XUL file. Take a look here for namespacing in firefox extensions.
What error do you get?
Edit:
Do you have initialized your jws object before to call browserSupportsWebSockets() ?
Like Pointy said, you need to load test.js after your jwebsocket.js file.
精彩评论