You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Cameron McCormack <ca...@mcc.id.au> on 2007/07/16 04:20:02 UTC

Re: SVG Javascript and HTML DOM

Hi Praveen.

Praveen Nayak:
> I have the Batik JSVGCanvas loaded inside an applet. This applet is
> hosted in an html page
>
>   I have a js file that is referenced inside the svg file that the
> canvas has loaded. Now, I am interested in accessing the HTML DOM
> inside the SVG Javascript.

OK.

>   I have read a previous post started by Gang Su "SVG Scripting beyond
> SVG itself" and I would like to validate my understanding in this forum
>
>   Accessing the Html DOM inside the SVG Javascript is not possible by
> any direct means. Am I correct here?

Not without a bit of work on the Java side.

>   I then tried accessing the HTML document object in the SVG
> Javascript by writing this method in the applet
>
> public Object getDocument(){
>  return JSObject.getWindow(this).getMember("document");
> }

>   After registering the applet with the Rhino engine with the name
> 'myApplet', I am able to access this document object in the SVG JS.

Cool.

> But then,
>
>   myApplet.getDocument().all
>   evaluates to null.
>
>   So, even if I am able to acces the HTML document object, I cannot
> its properties or call methods on it. Is this understanding right?

The problem is that the object returned by JSObject.getMember(String) is
another JSObject, and Batik’s use of Rhino doesn’t wrap this object to
provide “normal” JS property access to the object.  Instead, you need to
use the JSObject methods (such as getMember).

> So, I have now thought of a workaround for this:
>   
> 1. I create a method in the applet called 
>   public Object executeMethod(String methodName, Object[] args){
>  return JSObject.getWindow(this).call(methodName, args);
> }
>
> 2. I register the applet with the RhinoScript engine in one of them
> JGVTTreeBuilder... methods so that the svg Javascript can access the
> applet and call the above method.
>
> 3. In the HTML file that contains the applet, I write a method with
> the above method name that would work on the HTML DOM and return the
> appropriate value back to the applet, which returns it back to the SVG
> JavaScript.

That should also work.  But you can work with the JSObject methods from
your SVG’s script, too.

I might look into writing a Rhino wrapper for JSObjects so that access
properties in the normal fashion will work.

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org