Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Editor insertHTML ?

Post Reply
mddmx
Posts: 14
Joined: Fri Dec 13, 2019 2:42 pm

Editor insertHTML ?

Post 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 ?
User avatar
salvadordf
Posts: 4571
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Editor insertHTML ?

Post 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.
mddmx
Posts: 14
Joined: Fri Dec 13, 2019 2:42 pm

Re: Editor insertHTML ?

Post 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.
User avatar
salvadordf
Posts: 4571
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Editor insertHTML ?

Post by salvadordf »

Please, download CEF4Delphi again.

I added a local image selector form to the EditorBrowser demo.
mddmx
Posts: 14
Joined: Fri Dec 13, 2019 2:42 pm

Re: Editor insertHTML ?

Post by mddmx »

Wow. Thank you very much. It works perfectly.
Post Reply