Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a content editable DIV that plays the role of a rich text box.
HTML
<div id='myRichTextBox' contenteditable='true'>
</div>

I need to insert some images to this text box, I used function execCommand, Like this:
JavaScript
document.execCommand("insertImage", false, imgLink);

Once this function executed, It insert an element <img src="imgLink"> to the text box.
But as we know a single tag in a standard HTML code must be either in the two following formats:
1. Start with <TagName> and ends with </TagName>
2. Be in format <TagName some attribute />

My problem is the inserted image element by the function execCommand is not in a standard format, And my XML parser fails with this HTML code.
How I can standard this HTML code? Please give me a solution.

Thanks in advance
abforce
Posted
Comments
Shubhashish_Mandal 28-Jun-13 4:38am    
execCommand return the expected result incase of insertImage. And <img src="imgLink"> is a valid html tag;
Ali Reza Barkhordari 28-Jun-13 4:42am    
But the closing tag is missed.This tag must be in format `<img src='imgLink' />` or `<img src='imgLink' ></img>` .
Shubhashish_Mandal 28-Jun-13 5:29am    
No, its not an invalid tag.Please see this link
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml_image_test
Ali Reza Barkhordari 28-Jun-13 5:44am    
But jQuery parser can not parse such html codes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900