Cannot Get a Reference to SVG Document

V

vunet.us

When I create <embed name='myembed'> object in HTML and say later on:

var svgDoc = document.myembed.getSVGDocument()

SVG document gets found. But when I create SVG document using DOM:

var embed = document.createElement('embed');
embed.setAttribute('name','myembed')
parent.appendChild(embed);

I get embed object but svg document cannot be referenced to it:

var svgDoc = document.myembed.getSVGDocument() ===> null

What happened? I need to create embed on the fly...
 
M

Martin Honnen

When I create <embed name='myembed'> object in HTML and say later on:

var svgDoc = document.myembed.getSVGDocument()

SVG document gets found. But when I create SVG document using DOM:

var embed = document.createElement('embed');
embed.setAttribute('name','myembed')
parent.appendChild(embed);

I get embed object but svg document cannot be referenced to it:

var svgDoc = document.myembed.getSVGDocument() ===> null

Which browser is that? Does it have native SVG support or does it use a
plugin for SVG support?
 
V

vunet.us

Yes it does. FF2. I think it takes some time to load SVG file. When I
put setTimeout('doMyFuncAgain()', 1000) if no SVG document found on
page after I create it, it works well then. Strange?
 
M

Martin Honnen

Yes it does. FF2. I think it takes some time to load SVG file. When I
put setTimeout('doMyFuncAgain()', 1000) if no SVG document found on
page after I create it, it works well then. Strange?

Not so strange, you can use a load event listener e.g.
var embed = document.createElement('embed');
embed.addEventListener('load', function (evt) {
// here you should be able to access
// this.getSVGDocument()
}, false);
embed.type = 'image/svg+xml';
embed.src = 'file.svg';
someElement.appendChild(embed);
 
V

vunet.us

Thank you,
let me try that

Martin said:
Not so strange, you can use a load event listener e.g.
var embed = document.createElement('embed');
embed.addEventListener('load', function (evt) {
// here you should be able to access
// this.getSVGDocument()
}, false);
embed.type = 'image/svg+xml';
embed.src = 'file.svg';
someElement.appendChild(embed);
 

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

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top