如何检查嵌入式SVG文档是否加载到html页面? [英] How to check if an embedded SVG document is loaded in an html page?
问题描述
我需要编辑(使用javascript)嵌入在html页面中的SVG文档。
I need to edit (using javascript) an SVG document embedded in an html page.
当加载SVG时,我可以访问SVG的dom和它的元素。但我无法知道SVG dom是否准备就绪,因此我无法在加载html页面时对SVG执行默认操作。
When the SVG is loaded, I can access the dom of the SVG and its elements. But I am not able to know if the SVG dom is ready or not, so I cant' perform default actions on the SVG when the html page is loaded.
访问SVG dom,我使用这段代码:
To access the SVG dom, I use this code:
var svg = document.getElementById("chart").getSVGDocument();
其中chart是embed元素的id。
where "chart" is the id of the embed element.
如果我在html文档准备就绪时尝试访问SVG,则以这种方式:
If I try to access the SVG when the html document is ready, in this way:
jQuery(document).ready( function() {
var svg = document.getElementById("chart").getSVGDocument();
...
svg总是为空。我只需要知道它何时不为空,所以我可以开始操纵它。
你知道是否有办法这样做?
svg is always null. I just need to know when it is not null, so I can start manipulate it. Do you know if there is a way to do it?
推荐答案
你可以经常尝试民意调查。
You could try polling every so often.
function checkReady() {
var svg = document.getElementById("chart").getSVGDocument();
if (svg == null) {
setTimeout("checkReady()", 300);
} else {
...
}
}
这篇关于如何检查嵌入式SVG文档是否加载到html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!