[Jslib] example code that doesn't work for me...

stknight at ultralifebatteries.com stknight at ultralifebatteries.com
Tue Sep 9 16:42:23 EDT 2003


please forgive the formatting (I hate Outlook too)

> -----Original Message-----
> From:	Pete Collins [SMTP:pete at mozdev.org]
> Sent:	Tuesday, September 09, 2003 3:15 PM
> To:	jslib at mozdev.org
> Subject:	Re: [Jslib] example code that doesn't work for me...
> 
> stknight at ultralifebatteries.com wrote:
> > Greetings,
> > 
> > I've just installed jslib today and have almost immediately run into
> > problems.
> > 
> > specifically, the example code below generates a "File is not defined"
> (line
> > 18) in the Javascript console.  The window appears, the buttons attempt
> to
> > work but that error definitely puts a crimp in what I want to do.
> > 
> > The splash screen (chrome://jslib/content/) from either the command line
> > (Cygwin) or in Mozilla's locator, no problem.
> > 
> > Windows 2000
> > Mozilla 1.4
> > 
> > I've seen similar errors reported in either your archives or via Google,
> but
> > nobody seems to have ever posted the fix.
> > 
> > Any suggestions?
> 
> Well, using Win 98, Mozilla 1.4, jslib 0.1.83. It worked fine for me.
	[SK]  Interesting, I'll have to play around with how Mozilla is
installed.

> Do note that i changed the local file path in the test from:
> 
>    var localFile = "/tmp/fubar.dat";
> 
> to a valid Win local file path
> 
>    var localFile = "c:\\tmp\\fubar.dat";
> 
> Hope this helps.
	[SK]  Success!  The Example Code below originally from the JSLlib
User Manual "A sample xul page using the file module" now works correctly.
	In my environment (at least) jslib gets very cranky if you try to
pass a unix-like path to File.  Also, it appears that homage must be paid to
the netscape.security.PrivilegeManager and jslib_filesystem must be
specifically included.

	I've included the functioning example code to (hopefully) save time
for other folk.

	[SK]  Example Code:
	<?xml version="1.0"?>
	<!DOCTYPE window>
	<window id="jslib-file-test"
	    style="background-color: #cccccc; width: 100px; height: 100px;"
	    xmlns:html="http://www.w3.org/1999/xhtml"
	
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
	>

	    <script type="application/x-javascript"
	        src="chrome://jslib/content/jslib.js"
	    />

	    <script type="application/x-javascript">
	        try {
	
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	            include( jslib_filesystem );
	            include( jslib_file );
	        }
	        catch( e )
	        {
	            alert( "includes failed with exception: " + e );
	        }
	        // a local file path
	        var localFile = "f:\\tmp\\fubar.dat";
	        var f = new File(localFile);
	    </script>

	    <vbox flex="1" pack="center">
	        <spacer flex="1" />
	        <button label="Function List" oncommand="alert(f.help);" />
	        <button label="exists" oncommand="alert( f.exists() );" />
	        <button label="create file" oncommand="if( !f.exists() )
f.create();" />
	        <spacer flex="1" />
	    </vbox>
	</window> 
>  


This message was scanned for viruses before being allowed to leave Ultralife Batteries mail servers.




More information about the Jslib mailing list