Javascript behaves differently when opened as file:// vs. from local web server

N

Nick

I have been tasked to figure out a way to communicate from a
JavaScript /XUL client to a server, but without using a web server.


I have been researching different possibilities, and I have come upon
<a href = "http://aflax.org">aflax</a>, which is a library for
imbedding flash in JavaScript. So far I have been able to get it to
connect, but only if the server script is running locally along with
the flash content and client. I am using the example of a chat
program at aflax.org - http://aflax.org/examples/sockets/sockets.html
.. you can see the example there but unfortunately the demo does not
work, and Aflax forums have not provided a response.


1) Why should the HTML file (with JavaScript and Aflax) act
differently when it is opened as a file:// as opposed to on a
localhost web server? It does not connect to the server when I simply
open the file from my filesystem rather than being served it on a web
server. The Firefox error console notes this error when I use the
filesystem method: __flash__argumentsToXML is not defined . This
error is not present when it is served from the web server, but a
google search doesn't yield any help for me - only the same function
embedded in lots of other code.

2) If I run the web server locally and open the HTML file, but run
the server (simply a perl script), it also does not connect to the
server. Someone suggested this may relate to setting the
crossdomain.xml. I Set it the domains to *, and it still did not
work. Because I am running it on a local LAN, i'm not even sure what
domain I would put there.

If this is an inappropriate place to post, I apologize, but I'm really
grasping at straws here - I don't know if the problem is JavaScript,
Flash code, Flash player settings, the Aflax library, or what. I did
go into the flashplayer settings here:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager02.html#118539
to allow this particular flash file to connect out to the Internet.

Thanks,
Nick
 
T

Thomas 'PointedEars' Lahn

Nick said:
I have been tasked to figure out a way to communicate from a
JavaScript /XUL client to a server, but without using a web server.

I have been researching different possibilities, and I have come upon
<a href = "http://aflax.org">aflax</a>, which is a library for
imbedding flash in JavaScript. So far I have been able to get it to
connect, but only if the server script is running locally along with
the flash content and client. I am using the example of a chat
program at aflax.org - http://aflax.org/examples/sockets/sockets.html
. you can see the example there but unfortunately the demo does not
work, and Aflax forums have not provided a response.

Having seen the example on the Aflax homepage, that library does not strike
me as being written by an individual who knows how to employ ECMAScript
implementations properly.
1) Why should the HTML file (with JavaScript and Aflax) act
differently when it is opened as a file:// as opposed to on a
localhost web server? It does not connect to the server when I simply
open the file from my filesystem rather than being served it on a web
server. The Firefox error console notes this error when I use the
filesystem method: __flash__argumentsToXML is not defined .

So it isn't defined, and you have to find out why -- Read the Source, Luke.
This error is not present when it is served from the web server, but a
google search doesn't yield any help for me - only the same function
embedded in lots of other code.
http://getfirebug.com/

I did go into the flashplayer settings here:
http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager02.html#118539
to allow this particular flash file to connect out to the Internet.

However, the ECMAScript implementation (here: JavaScript) does not care
about Flash Player settings, and the Same Origin Policy forbids and
prevents that kind of access.


PointedEars
 
N

Nick

Having seen the example on theAflaxhomepage, that library does not strike
me as being written by an individual who knows how to employ ECMAScript
implementations properly.


So it isn't defined, and you have to find out why -- Read the Source, Luke.

The reference to that function in the library / aflax.js file is all
there is. Adobe's docs don't show any help here either:
http://www.google.com/search?q=site...s=org.mozilla:en-US:official&client=firefox-a
About the only place I can find someone referring to this function
(and not simply listing some code) is here:
http://lists.deconcept.com/pipermail/swfobject-deconcept.com/2006-July/000794.html
..

So I still don't really know what to make of it - unless my opening
the file locally, some library or other file is not being loaded,
which has the definition in it.
However, the ECMAScript implementation (here: JavaScript) does not care
about Flash Player settings, and the Same Origin Policy forbids and
prevents that kind of access.
I have downloaded firebug and will try to use that. I had not heard
of the Same Origin Policy, but according to this:
http://en.wikipedia.org/wiki/Same_origin_policy , it doesn't apply if
I am opening the file locally.

Thank you for responding, I would appreciate any more direction here.

nick
 
T

Thomas 'PointedEars' Lahn

Nick said:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
However, the ECMAScript implementation (here: JavaScript) does not care
about Flash Player settings, and the Same Origin Policy forbids and
prevents that kind of access.

[...] I had not heard of the Same Origin Policy, but according to this:
http://en.wikipedia.org/wiki/Same_origin_policy , it doesn't apply if
I am opening the file locally.

Unless I have misunderstood you, you are trying to open a resource with a
http:// URI from a resource accessed with a file:// URI. The Same Origin
Policy forbids that and there is no workaround other than in Geckos to lower
the UA's security settings via a user preference (which strongly recommended
against nowadays).


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top