Chrome error with NO_MODIFICATION_ALLOWED_ERR DOM Exception 7

Posted by HP on Stack Overflow See other posts from Stack Overflow or by HP
Published on 2010-03-26T07:39:06Z Indexed on 2010/03/26 7:43 UTC
Read the original article Hit count: 495

Filed under:
|
|
|
|

I have below code to insert a style into DOM (there is a use case for injecting style into DOM so please don't ask why or say to load the css in .css file).

<script type="text/javascript">
window.onload = function()
{
    var bmstyle = document.createElement('style');
    bmstyle.setAttribute('type', 'text/css');
    var styleStr = "#test-div {background:#FFF;border:2px solid #315300;";
    bmstyle.innerHTML = styleStr;
    document.body.appendChild(bmstyle);
}

</script>

If I run in Firefox, it works fine. But I got this error in Google Chrome:

Line bmstyle.innerHTML = styleStr;
Uncaught Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7

Does anyone have a fix? Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html