Page 1 of 1

Editor insertHTML ?

Posted: Thu Dec 19, 2019 10:29 pm
by mddmx
I am trying to work from your Editor demo and ran into a couple of questions.

When I look at the function to insert and image, it works fine but if I try to insert a local png or jpg image from you local drive instead of a url it seems to do nothing at all. file:///c:/test/image.png

So, I then moved on to insertHTML. If I insert something very simple such as this it works

Test := '<b> time </b>';
TempCode := 'document.execCommand("insertHTML", false, "' + Test + '");';
Chromium1.ExecuteJavaScript(TempCode, 'about:blank');

but if I try this is does absolutely nothing. Test := 'Now is the<b> time </b>for <font color="#ff0000">all good men&nbsp;</font>'

Do you know if there Is a special format that I should be following ?

Re: Editor insertHTML ?

Posted: Fri Dec 20, 2019 9:47 am
by salvadordf
Hi,
mddmx wrote: Thu Dec 19, 2019 10:29 pm I am trying to work from your Editor demo and ran into a couple of questions.

When I look at the function to insert and image, it works fine but if I try to insert a local png or jpg image from you local drive instead of a url it seems to do nothing at all. file:///c:/test/image.png
Try adding the image as a DATA URL.
mddmx wrote: Thu Dec 19, 2019 10:29 pm So, I then moved on to insertHTML. If I insert something very simple such as this it works

Test := '<b> time </b>';
TempCode := 'document.execCommand("insertHTML", false, "' + Test + '");';
Chromium1.ExecuteJavaScript(TempCode, 'about:blank');

but if I try this is does absolutely nothing. Test := 'Now is the<b> time </b>for <font color="#ff0000">all good men&nbsp;</font>'

Do you know if there Is a special format that I should be following ?
The color attribute is using double quotes and the Test variable is enclosed in double quotes. Try replacing the color double quotes by single quotes. Use the #39 Delphi char or the quotedstr Delphi function if necessary.

Re: Editor insertHTML ?

Posted: Fri Dec 20, 2019 4:13 pm
by mddmx
Thank you for the reply. I did manage to get the text inserted by replacing the "" with ' so that is ok but I just cannot insert an image from a file. I have tried inserting any simple image as a data uri (after triple checking that the uri was valid) . It just does nothing.

URL := '<img src="data:image/png;base64,' + ConvertFileToBase64(PngFileName) + '"/>';
TempCode := 'document.execCommand("insertImage", false, "' + URL + '");';
Chromium1.ExecuteJavaScript(TempCode, 'about:blank');

Is it possible that there is some setting that is blocking it in the demo app ? I did try setting the following with no change in effect.
Chromium1.Options.WebSecurity := STATE_DISABLED;
Chromium1.Options.FileAccessFromFileUrls := STATE_ENABLED;
Chromium1.Options.LocalStorage := STATE_ENABLED;

If anyone has an example of inserting a data uri I would sure be excited to try it.

Re: Editor insertHTML ?

Posted: Sat Dec 21, 2019 11:33 am
by salvadordf
Please, download CEF4Delphi again.

I added a local image selector form to the EditorBrowser demo.

Re: Editor insertHTML ?

Posted: Sat Dec 21, 2019 2:19 pm
by mddmx
Wow. Thank you very much. It works perfectly.