javascript - Can I insert a block of HTML into an iframe if it has quotation marks? -
essentially, want able add accordion html document displayed in iframe. such, trying:
function insert(framename, text, replacecontents) { document.getelementbyid('framename').focus() if(replacecontents==null){replacecontents=false;} if(!replacecontents){ var sel=document.getelementbyid('framename').contentwindow.getselection() sel.collapsetostart() } html = "<div id="accordion"> <h3>section 1</h3> <div> <p>text 1</p> </div> <h3>section 2</h3> <div> <p>text 2</p> </div> </div>" document.getelementbyid('framename').contentwindow.document.execcommand('inserthtml', false, html); }; the problems i'm experiencing @ moment due use of multiple lines (is there way leave formatted in way have wrapped in quotation marks?) , quotation marks themselves, there in html, isn't able full thing (even when lines right).
is there way around this, should adding end of line (like ...) keep doing, , pit instead of or next quotation marks make them appear correctly (in matlab double it's '' instead of ')?
you should escape double-quotes backslash add backslash end of each line avoid breaking string.
var html = "<div id=\"accordion\">\ <h3>section 1</h3>\ <div>\ <p>text 1</p>\ </div>\ <h3>section 2</h3>\ <div>\ <p>text 2</p>\ </div>\ </div>";
Comments
Post a Comment