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

Accessing SVG DOM from HTML Javascript

650 views
Skip to first unread message

Lester

unread,
Aug 17, 2007, 3:10:07 PM8/17/07
to
I have a html page containing a <object id="aa" data="aa.svg" ....>.
Now what I want to do is change the color of some element inside the
svg when some link in the html doc is clicked. I'm using Javascript to
do this:

svgdoc = document.getElementById('aa').getSVGDocument();
element = svgdoc.getElementsByTagName('xxx')[0];
.....

The problem is: element gives an undefined value!

I don't know how to access elements just using html javascripts (I
mean not svg javascripts).
Any ideas? Thanks.

Thomas 'PointedEars' Lahn

unread,
Aug 17, 2007, 3:41:08 PM8/17/07
to
Lester wrote:
> I have a html page containing a <object id="aa" data="aa.svg" ....>.
> Now what I want to do is change the color of some element inside the
> svg when some link in the html doc is clicked. I'm using Javascript to
> do this:
>
> svgdoc = document.getElementById('aa').getSVGDocument();
> element = svgdoc.getElementsByTagName('xxx')[0];
> .....
>
> The problem is: element gives an undefined value!

Probably `svgdoc' gives `undefined', too, and you have two errors in the
Error Console like

| document.getElementById('aa').getSVGDocument is not a function
| svgdoc is not defined

> I don't know how to access elements just using html javascripts (I
> mean not svg javascripts).
> Any ideas?

ISTM that getSVGDocument() is a method provided by the Adobe SVG Viewer
plugin[1] as it is not defined in W3C DOM Level 2 HTML[2] or the W3C SVG
DOM[3]. Several UAs, including Firefox 1.5+, have native SVG support, so
you need to use

var svgdoc = document.getElementById('aa').contentDocument;

for those instead.[4]

Object references should be subject to a type-converting test before being
used, and DOM methods should be feature-tested before being called.[5]

> Thanks.

You're welcome.


PointedEars
___________
[1] http://support.adobe.com/devsup/devsup.nsf/docs/50523.htm
[2] http://www.w3.org/TR/DOM-Level-2-HTML/
[3] http://www.w3.org/TR/SVG11/svgdom.html
[4] http://wiki.mozilla.org/SVG:GetSVGDocument
[5] http://www.jibbering.com/faq/faq_notes/not_browser_detect.html#bdFD
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

Message has been deleted

Martin Honnen

unread,
Aug 18, 2007, 8:22:38 AM8/18/07
to
Thomas 'PointedEars' Lahn wrote:

> ISTM that getSVGDocument() is a method provided by the Adobe SVG Viewer
> plugin[1] as it is not defined in W3C DOM Level 2 HTML[2] or the W3C SVG
> DOM[3].

The SVG 1.1 specification defines it here:
<URL:http://www.w3.org/TR/SVG11/struct.html#InterfaceGetSVGDocument>

--

Martin Honnen
http://JavaScript.FAQTs.com/

Thomas 'PointedEars' Lahn

unread,
Aug 18, 2007, 9:48:15 AM8/18/07
to
Martin Honnen wrote:
> Thomas 'PointedEars' Lahn wrote:
>> ISTM that getSVGDocument() is a method provided by the Adobe SVG Viewer
>> plugin[1] as it is not defined in W3C DOM Level 2 HTML[2] or the W3C SVG
>> DOM[3].
>
> The SVG 1.1 specification defines it here:
> <URL:http://www.w3.org/TR/SVG11/struct.html#InterfaceGetSVGDocument>

Thanks. Are you implying that Firefox' behavior is a bug?


PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>

Martin Honnen

unread,
Aug 18, 2007, 10:15:34 AM8/18/07
to
Thomas 'PointedEars' Lahn wrote:

> Are you implying that Firefox' behavior is a bug?

It is open here: <https://bugzilla.mozilla.org/show_bug.cgi?id=287465>

0 new messages