JS-EAI with *JS*-callback 
Author Message
 JS-EAI with *JS*-callback

Hello all.

Thanks to Paul S. Hoffman who made me discover the Javascript EAI in his
two articles on the subject (see:
http://www.*-*-*.com/ ). Without him, my further
step could not be possible (while i'm the only responsible for my
eventual mistakes).

Here i'll submit a way to work around the no-callback limitation. That
is, there *is* a way to get feedback from the vrml world in Javascript -
limited to CosmoPlayer 2.0 running in Netscape 4.0x, of course.

The basic concept is that "javascript" is an URL protocol to the browser
- as, say, "http" - but a very special one, since it allowes running of
JS code upon a *page* request. In fact, we are already used to this
behaviour: we call JS functions outside the VRML world through Anchor

So, what we need is just a Script node that gets the needed event and
forwards it to an external JS function, by calling the loadURL() method
of Browser!

Below is a sample that will tell much more than my poor English.

Comments appreciated.

Regards, julio di egidio

    <SCRIPT LANGUAGE="Javascript"><!--
      function cbIsBound(which) {
          switch(which) {
            case 0:
              Vs.value = "\"V0\"";
            case 1:
              Vs.value = "\"V1\"";
              Vs.value = "Unknown";
    // --></SCRIPT>
    <EMBED SRC="Callback.wrl" HEIGHT="200" WIDTH="300">
      Selected Viewpoint:
      <INPUT NAME="Vs" TYPE="text" VALUE="Unknown" SIZE="7"

#VRML V2.0 utf8

DEF V0 Viewpoint {
  position 0 0 5
  description "V0"


DEF V1 Viewpoint {
  position 0 0 10
  description "V1"


Shape { geometry Box { size 1 1 1 } }

DEF SC Script {
  eventIn SFBool V0_isBound
  eventIn SFBool V1_isBound

  field MFString V0_cbIsBound ["javascript:self.cbIsBound(0)"]
  field MFString V1_cbIsBound ["javascript:self.cbIsBound(1)"]
  field MFString Vs_par       []

  url "javascript:
    function initialize() {
      Browser.loadURL(V0_cbIsBound, Vs_par);

    function V0_isBound(val) {
      if(val) Browser.loadURL(V0_cbIsBound, Vs_par);

    function V1_isBound(val) {
      if(val) Browser.loadURL(V1_cbIsBound, Vs_par);


ROUTE V0.isBound TO SC.V0_isBound
ROUTE V1.isBound TO SC.V1_isBound

Wed, 22 Nov 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. js.exception 3279.js

2. NB. gray.js: a J verb that generates a grayscale postscript image from a 2d array

3. lapackTest.js

4. profile.js

5. J script file profile.js

6. JS valueOf() in RB ?

7. JS for functional programming?

8. JS for functional programming?

9. prefs.js question

10. JS / VRML / HTML / camera binding

11. help: js generated vrml

12. my big CLASSPATH confusion (J. and JS. dont work in CP2.1 / NS405)


Powered by phpBB® Forum Software