重新初始化SVGweb for ajax [英] Reinitialize SVGweb for ajax

查看:156
本文介绍了重新初始化SVGweb for ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要简单地加载(打开)页面,我就可以使用SVGweb.

I have no problem using SVGweb when page is simply loaded (opened).

如何重新初始化SVGweb以便在页面上重新绘制所有SVG?

How is it possible to reinitialize SVGweb in order to redraw all SVG on the page?

换句话说,我需要SVGweb重新扫描并重新呈现页面上的所有内容.

Anotherwords I need SVGweb to rescan and rerender everything on the page.

来源(来自此):

<script type="image/svg+xml">
  <svg>
    ...
  </svg>
</script>

对此(就像SVGweb si只是在打开页面时所做的那样):

to this (like SVGweb si doing that when simply open the page):

<svg>
...
</svg>

我需要这个,因为我使用ajax更改了SVG图形,并且需要在页面上重新呈现它.

I need this because I change the SVG graphics using ajax and need to rerender it on the page.

推荐答案

使用新的SVGweb代码(通过Ajax)更改DOM后

After the DOM is changed with a new SVGweb code (through Ajax)

<script type="image/svg+xml">
  <svg>
    ...
  </svg>
</script>

需要执行以下操作: svgweb._onDOMContentLoaded();

need to execute this: svgweb._onDOMContentLoaded();

但是在注释SVGweb svg-uncompressed.js或svg.js的核心源代码中的一行之前,

But before need to comment a line in the core source of SVGweb svg-uncompressed.js or svg.js

svg-uncompressed.js 来自

svg-uncompressed.js from

    if (arguments.callee.done) {
      return;
    }

    if (arguments.callee.done) {
      //return;
    }

svg.js:查找并删除它:

svg.js: find and delete this:

arguments.callee.done=true;

或替换为

arguments.callee.done=false;

编辑:

另一个适用于IE9的修复程序:

One more fix to work for IE9:

对于svg.js

来自

var a=document.getElementById("__ie__svg__onload");if(a){a.parentNode.removeChild(a);a.onreadystatechange=null}

var IEv=parseFloat(navigator.appVersion.split("MSIE")[1]);if(IEv<9){var a=document.getElementById("__ie__svg__onload");if(a){a.parentNode.removeChild(a);a.onreadystatechange=null;a=null;}}

对于svg-uncompressed.js

for svg-uncompressed.js

来自

    // cleanup onDOMContentLoaded handler to prevent memory leaks on IE
    var listener = document.getElementById('__ie__svg__onload');
    if (listener) {
      listener.parentNode.removeChild(listener);
      listener.onreadystatechange = null;
      listener = null;
    }

    // cleanup onDOMContentLoaded handler to prevent memory leaks on IE
    var IEv=parseFloat(navigator.appVersion.split("MSIE")[1]);
    if (IEv<9) {
        var listener = document.getElementById('__ie__svg__onload');
        if (listener) {
          listener.parentNode.removeChild(listener);
          listener.onreadystatechange = null;
          listener = null;
        }
    }

这篇关于重新初始化SVGweb for ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆