문제

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);   
   }
}
도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top