Chrome error with NO_MODIFICATION_ALLOWED_ERR DOM Exception 7
I think it's because you are using innerHTML
when everywhere else you are using XML syntax. Try:
bmstyle.nodeValue = styleStr;
Suggestion 2:
It might also be because you are trying to set the innerHTML of a an element not yet in the HTML DOM. If that's the case, my first suggestion should still hold up, or you can go with:
document.body.appendChild(bmstyle);bmstyle.innerHTML = styleStr;
I'm not sure if you'd need a line inbetween to reclaim the element or if the bmstyle would still point to it.
Just a note for future reference... I'm using the following function to dynamically create CSS styles. I found that using textContent worked the best.
This breaks on Safari
el.innerHTML = css.join('\n');
This breaks on FireFox
el.innerText = css.join('\n');
The following is my final code that works on both browsers. IE not tested...
/*** Write out stylesheets to the page.* * @param {array} css*/function print_css(css) { var headTag = document.getElementsByTagName('head')[0], el = document.createElement('style'); el.type = 'text/css'; el.textContent = css.join('\n'); headTag.appendChild(el);}
Me too, I had this problem, try this one:
bmstyle.value = styleStr;