SVG と JavaScript に問題があります。
このコードは期待どおりに動作します。
function initSvg(width) {
SVGRoot = document.getElementsByTagName('svg')[0];
console.log(SVGRoot.currentScale); // Displays '1' which is OK
しかし、 currentScale パラメータを次のように再割り当てしようとすると:
function initSvg(width) {
SVGRoot = document.getElementsByTagName('svg')[0];
SVGRoot.currentScale = parseFloat(width)/400;
console.log(SVGRoot.currentScale); // Should display some floating point number
エラーが発生します
Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) nsIDOMSVGSVGElement.currentScale]
アラートは実行されません。SVGRoot.currentScale への割り当ての何が問題になっていますか?
アップデート:
使用するとエラーが消えます
SVGRoot.setAttribute('currentScale', parseFloat(width)/400);
また
SVGRoot.setAttributeNS(null, 'currentScale', parseFloat(width)/400);
しかし、 currentScale の実際の値は変わりません。setAttribute に何が渡されても、1 のままです。