搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

getNumberOfChars() returns 0 on tspans

  • 無回覆
  • 1 有這個問題
  • 6 次檢視
more options

I'm doing some work with SVGs and hit a problem with tspan elements returning 0 for getNumberOfChars().

I have searched Bugzilla and came up with an issue closed as fixed some 15 years ago (https://bugzilla.mozilla.org/show_bug.cgi?id=339039) which includes a test case (reproduced below).

In Firefox, this now reports 0 for all 4 tspans, however in Chrome and IE it reports 4 for all tspans which is what I would expect.

Is there some nuance I'm missing or is this a regression?

<svg xmlns="http://www.w3.org/2000/svg" onload="window.setTimeout('delay()', 1000);"> <script></script> <text fill="black" transform="translate(0,20)"> <tspan id="t1">Test</tspan> <tspan id="t2">Test</tspan> <tspan id="t3">Test</tspan> <tspan id="t4">Test</tspan> </text> </svg>

I'm doing some work with SVGs and hit a problem with tspan elements returning 0 for getNumberOfChars(). I have searched Bugzilla and came up with an issue closed as fixed some 15 years ago (https://bugzilla.mozilla.org/show_bug.cgi?id=339039) which includes a test case (reproduced below). In Firefox, this now reports 0 for all 4 tspans, however in Chrome and IE it reports 4 for all tspans which is what I would expect. Is there some nuance I'm missing or is this a regression? <?xml version="1.0" ?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg xmlns="http://www.w3.org/2000/svg" onload="window.setTimeout('delay()', 1000);"> <script><![CDATA[ function delay() { alert( "t1:" + document.getElementById("t1").getNumberOfChars() + "\nt2:" + document.getElementById("t2").getNumberOfChars() + "\nt3:" + document.getElementById("t3").getNumberOfChars() + "\nt4:" + document.getElementById("t4").getNumberOfChars() ); } ]]></script> <text fill="black" transform="translate(0,20)"> <tspan id="t1">Test</tspan> <tspan id="t2">Test</tspan> <tspan id="t3">Test</tspan> <tspan id="t4">Test</tspan> </text> </svg>