Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

svg and javascript embedded in html

93 views
Skip to first unread message

uddy

unread,
Sep 4, 2009, 3:32:08 AM9/4/09
to
Hallo,

I have svg file with javascript in it to allow me to manipulate the
objects. This svg I've embedded in an html file. From the html file i
access the nodes of the svg part in this file like this:

document = window.document.svg1.getSVGDocument();
svgElement = document.getElementById("elementname");

But now I need to use also some of the Variables in the JavaScript
part of the file. Is it possible to access them form the html(with
javascript of course) file like it's possible with the svg part? Right
now I'm putting all the values I need in a hidden Textnode and get
them as every other svg node. But thats not very effectiv and looks
ugly...

thx for any help.


mario

HelderMagalhaes

unread,
Sep 4, 2009, 4:59:18 AM9/4/09
to
Hi mario,


> document = window.document.svg1.getSVGDocument();
> svgElement = document.getElementById("elementname");

There are several things I'd suggest differently:
1. Making an attribute to the "document" (special) variable may have
undesired results. Consider using another variable such as "svgEle";
2. Acessing the element's identifier though it's JavaScript variable
("document.svg1") is deprecated (there should be warnings in the Error
Console). You should use "document.getElementById" instead;
3. Best (only?) way to get a pointer to the SVG document's DOM in
Gecko is "CONTAINER_OBJECT_DOM.contentDocument" [1].

Summing up, you example would turn into:
svgDocument = document.getElementById("svg1").contentDocument;
svgElement = svgDocument.getElementById("elementname");


> But now I need to use also some of the Variables in the JavaScript
> part of the file. Is it possible to access them form the html(with
> javascript of course) file like it's possible with the svg part? Right
> now I'm putting all the values I need in a hidden Textnode and get
> them as every other svg node. But thats not very effectiv and looks
> ugly...

I've found this paragraph to be a little confusing. Please clear [2]
it up a if possible.


> thx for any help.

Hope this helps,
Helder


[1] http://jwatt.org/svg/demos/getSVGDocument.html
[2] http://www.catb.org/~esr/faqs/smart-questions.html#writewell

Boris Zbarsky

unread,
Sep 4, 2009, 8:30:45 AM9/4/09
to
uddy wrote:
> document = window.document.svg1.getSVGDocument();
...

> But now I need to use also some of the Variables in the JavaScript
> part of the file. Is it possible to access them form the html(with
> javascript of course)


window.document.svg1.contentWindow.variableName

-Boris

uddy

unread,
Sep 4, 2009, 10:40:07 AM9/4/09
to
Hi Helder,

>1. Making an attribute to the "document" (special) variable may have
>undesired results. Consider using another variable such as "svgEle";

Actually the variable had once the name svgdoc I don't know when I
changed it or why.
But thanks for reminding me.

>  3. Best (only?) way to get a pointer to the SVG document's DOM in
> Gecko is "CONTAINER_OBJECT_DOM.contentDocument" [1].

I'm using the IE for this "project", so contentDocument doesn't work
(didn't know until i tried it today).
But the first part that tries to get an svg from an embed tag works.
With firefox both methods work of course (embed and object), but
firefox doesn't support all the features I need
(or i couldn't figure out how to get them working), the main reason
I'm using IE, however, is because
I have to integrate this code in some interface that was built for IE
only, because it needs
some ActiveX stuff (Cortona for VRML etc.).

> Summing up, you example would turn into:
>  svgDocument = document.getElementById("svg1").contentDocument;
>  svgElement = svgDocument.getElementById("elementname");

This doesn't work because IE doesn't know contentDocument(I guess),
and because svg1 is not the 'id' of the object but the 'name' and of
course it's in an embed tag
not an object tag. But I should have mentioned this before.

> I've found this paragraph to be a little confusing. Please clear [2]
> it up a if possible.

What I meant was, I have some javascript code in the svg file,
(when I click on the graphics they use onclick etc. to perform some
actions)
and now I would like to access the variables which are in the
javascript code that is in the svg file, from the html file.
I think Boris who answered after you got it.
But the problem is still this doesn't work with IE.

I should have mentioned at the start that this needs to work with the
IE,
but I didn't know that the difference between gecko and IE-engine is
so huge.
At leaset I hoped it is not.

This is how I use the svg in the html:
embed id ="bp_man" src="click_con_enhanced.svg" name="svg1"
type="image/svg-xml" height="400" width="500"

I hope someone (although it's a mozilla group) knows a solution that
works with the embed tag and not only with the object tag.

Thank you anyway for trying,

Mario


uddy

unread,
Sep 4, 2009, 10:45:46 AM9/4/09
to
Hi Boris,

> window.document.svg1.contentWindow.variableName
>
> -Boris

this is what I need, but unfortunately it works only on Firefox and
doesn't work with the IE.
I should have mentioned at the start that I'm using IE. sorry!


Mario

HelderMagalhaes

unread,
Sep 7, 2009, 4:48:48 AM9/7/09
to
> >  3. Best (only?) way to get a pointer to the SVG document's DOM in
> > Gecko is "CONTAINER_OBJECT_DOM.contentDocument" [1].
>
> I'm using the IE for this "project", so contentDocument doesn't work
> (didn't know until i tried it today).

Humm, I see... :-p

This mailing list is dedicated to the Gecko (Firefox etc.)
implementation of SVG. You are invited to post generic SVG questions
into "SVG Developers" [1].

If you are using IE, then I imagine (as IE has no native SVG support)
you are either using ASV (or another plug-in) or even the SVG Web [2]
Flash+JS shim. The latter has a dedicated forum, the first is
abandoned by the vendor (Adobe), so you may try getting support on the
already stated generic list [1].


Regards,
Helder


[1] http://tech.groups.yahoo.com/group/svg-developers/
[2] http://code.google.com/p/svgweb/

0 new messages