innerHTML and style attributes

B

brian4cards

I have an application where a user can create a newsletter with a
contenteditable div box and submit it to a database. The problem occurs
when the user tries to edit their newsletter. The edit page looks
exactly like the create page only their already created newsletter is
supposed to appear in the contenteditable div box. To do this I
retrieve the information from the database in the server side. Then I
have the following client side script.

window.onload=doInit
function doInit() {
var content = "<%=sContent%>";
div.innerHTML = content;
}

This seems to work in all cases except if the HTML to be displayed
contains any style attributes. For example, if any of the text has
background color then the HTML code will have the tag <font
style="bacground-color: #000000"> and this will cause nothing to appear
in the div box. Has anyone run into this problem or know how to fix it?
 
R

RobG

brian4cards said:
I have an application where a user can create a newsletter with a
contenteditable div box and submit it to a database. The problem occurs
when the user tries to edit their newsletter. The edit page looks
exactly like the create page only their already created newsletter is
supposed to appear in the contenteditable div box. To do this I
retrieve the information from the database in the server side. Then I
have the following client side script.

window.onload=doInit
function doInit() {
var content = "<%=sContent%>";
div.innerHTML = content;
}

This seems to work in all cases except if the HTML to be displayed
contains any style attributes. For example, if any of the text has
background color then the HTML code will have the tag <font
style="bacground-color: #000000"> and this will cause nothing to appear
in the div box. Has anyone run into this problem or know how to fix it?

Have you tried changing the *background-color* property? It works for
me. :)

I'd also suggest replacing the deprecated font element with a span.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top