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 </font>'
Do you know if there Is a special format that I should be following ?
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.
Editor insertHTML ?
- salvadordf
- Posts: 4572
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Editor insertHTML ?
Hi,
Try adding the image as a DATA URL.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
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 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 </font>'
Do you know if there Is a special format that I should be following ?
Re: Editor insertHTML ?
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.
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.
- salvadordf
- Posts: 4572
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Editor insertHTML ?
Please, download CEF4Delphi again.
I added a local image selector form to the EditorBrowser demo.
I added a local image selector form to the EditorBrowser demo.
Re: Editor insertHTML ?
Wow. Thank you very much. It works perfectly.