Question

I was building an WYSIWYG editor for my website. I want to be able to resize images while user is inserting image into text. How to do it ? This code is not working.

this the code what i used.

function iImage(){  
   var imgSrc = prompt('Enter image location', '');  
   imgSrc.style.height='100px';
   imgSrc.style.width='50px';
   if(imgSrc != null){
       richTextField.document.execCommand('insertimage', false, imgSrc);   
   }
}
Was it helpful?

Solution

I don't know what sort of a WYSIWYG editor you are building or what those functions are doing, though at a glance I would advise to try setting the height and width attributes, not styles :

function iImage(){  
   var imgSrc = prompt('Enter image location', '');  
   imgSrc.height='100px';
   imgSrc.width='50px';
   if(imgSrc != null){
       richTextField.document.execCommand('insertimage', false, imgSrc);   
   }
}

As the corrseponding HTML should be

<img src="..." height="100px" width="500px">

not

<img src="..." style="height100px;width:500px;">

EDIT:

You can find the solution here: How to get the image element after insert using execCommand?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top