无法在具有特定高度和宽度的webview的光标位置插入图像

JavaScript:Not able to insert image at cursor position of webview with specific Height and Width

本文关键字:webview 光标 位置 图像 插入 高度      更新时间:2023-09-26

我正在尝试使用WebView实现RichTextEditor。

我使用以下代码插入图像。它工作得很好。

webview.loadUrl("javascript: 
                   (function () { document.execCommand('insertImage', 'false','"
                + selectedImagePath +"');})()");

要指定高度和宽度,我使用以下命令,但它不起作用。

String imagSpec =   " width=" + 200 + " height=" + 200 + " border= 5" ;
webview.loadUrl("javascript(function () {     
        document.execCommand('insertImage', 'false','"
        + selectedImagePath +imagSpec+ "');})()");

以下代码为我工作。

  String exeSucess="document.execCommand('insertHtml', false,'<img   +
  src='"http://www.developphp.com/images/home_over.png'" +
  height=200 width=auto style='"object-fit=contain;'"></img>');";

我没有调用'insertImage'命令,而是使用'insertHtml'命令,在光标位置插入图像标签。

谢谢