javascript - svg-insertAdjacentHTML is not working on firefox version 35 and below? -


i'm trying draw line using svg. used insertadjacenthtml. working on chrome not working in firefox.

my html code follow

<div style="height:330px; width:1100px; background:#313131; margin:0 auto; ">     <svg id='svg_main' height="330" width="1100"></svg> </div> 

my javascript follow

var svgid = document.getelementbyid('svg_main'); var str_lne = 60; var data = '<path id="lineab" d="m 50 '+str_lne+' l 1050 '+(str_lne)+'" transform="translate(0.5,0.5)"  stroke="#707073" fill="none"  storke-width="1px" opacity="1" ></path>'; svgid.insertadjacenthtml('beforeend',data); 

it doesn't run localhost on firefox(below 35).

for example,

i open firefox , enter url (localhost/svgtest.html) svg line not showing. but, save page ctrl+s , open firefox shows line.

run on firefox using localhost simply open file on firefoxplease me out problem , clarify reson of problem.

please replace following:

svgid.insertadjacenthtml('beforeend', data); 

with following:

console.log('svg\'s ns before insertion: ' + svgid.namespaceuri); svgid.insertadjacenthtml('beforeend', data); console.log('svg\'s ns after insertion: ' + svgid.namespaceuri); pathel = document.getelementbyid('lineab'); console.log('path\'s ns (after insertion): ' + pathel.namespaceuri); 

try firefox 35 or below. see namespace of svg element before , after call insertadjacenthtml , namespace of path element is, after has been inserted.

you try this jsfiddle, contains modification suggested above.

what encounter related this bug report. fix bug landed on firefox 36. , excluding firefox 36, messing inner html of svg element not respect element's deduced svg namespace , elements inserted belong xhtml namespace. regarded, then, html element, path element #lineab make no sense , would, thus, disappear page. (here speculation), since inserted path element's namespace (xhtml) not appear in dom, not saved when saving page. so, when opening saved page, path element's namespace correctly deduced (possibly inheriting svg element), resulting in svg appearing should.

a duplicate of bug report mentioned above this bug report , provided here more insight.

i tried approach suggested above in commercial cross-browser testing platform using vista , firefox 35 (i live dangerously) , console log svg/svg/xhtml. using firefox 36 console log svg/svg/svg.

what works in firefox 35 appending path svg this:

var svgid = document.getelementbyid('svg_main'); var str_lne = 60; var pathel = document.createelementns('http://www.w3.org/2000/svg', 'path'); pathel.setattribute('id', 'lineab'); pathel.setattribute('d', 'm 50 ' + str_lne + ' l 1050 ' + str_lne); pathel.setattribute('transform', 'translate(0.5,0.5)'); pathel.style.stroke = '#707073'; pathel.style.strokewidth = '1px'; svgid.appendchild(pathel); 

jsfiddle here. is, create elements explicity , not insert html directly.

the million dollar question now. why care firefox 35 or below?


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -