1、改变 embed 标签的 src 属性:通过js 直接改变好像不怎么行。我用的方法是先删除embed 标签,再js 添加一个标签,再给embed 的src 赋值。
var divoo = window.document.getElementById("divsvg");
var svgoo = window.document.getElementById("svgmap");
cleartimer();
divoo.removeChild(svgoo);
var svg = document.createElement("embed");
svg.setAttribute("id", "svgmap");
svg.setAttribute("type", 'image/svg+xml');
svg.setAttribute("width", '100%');
svg.setAttribute("height", '100%');
svg.setAttribute("src", 'svg/fan.svg'); //这里必须输入svg源
divoo.appendChild(svg);
2、document.getElementById('svgId'). getSVGDocument();的方法得到SVG Doc对象,但此方法存在两个问题:一是opera不支持getSVGDocument方法,二是对于动态创建的embed对象并不会马上被呈现,从而无法立刻得到SVGDocument对象,下面的方法会出错。
var body=document.getElementsByTagName('body')[0];
var svg=document.createElement("embed");
svg.setAttribute("id",id);
svg.setAttribute("type",'image/svg+xml');
svg.setAttribute("width",'100%');
svg.setAttribute("height",'100%');
svg.setAttribute("src",'a.svg');
body.appendChild(svg);
var svgdoc=svg.getSVGDocument();
在IE下出错,说找不到svg对象。
解决办法,在加载完 svg 文件后,设置一个延迟(500ms),然后再使用svg.getSVGDocument();方法
setTimeout("svg.getSVGDocument()", 500);
3、在向svg 文件添加 另外的svg 文件时,需注意文件里面的元素的 ID,如果有相同的ID,在显示的时候会出现意想不到的错误。
4、asp 页面通过oBao.open("POST","drawconn.asp?a="字体",false) 传递的汉字乱码。