How to use absolute URLs when saving image sources to a database from CKEDITOR

I use CKEDITOR to create newsletters. Everything went fine, but when I send the newsletters by e-mail, the images stored there are not displayed. The problem was caused by CKEDITOR, using a relative path for image sources, for example. <img src='/newsletter_images/news1/img1.jpg'> .

I want CKEDITOR to use absolute URLs, for example:

 <img src='http://www.mydomain.com/newsletter_images/news1/img1.jpg' /> 

The initialization I tried looks like this:

 <script type="text/javascript"> $(document).ready(function() { $('#editor1').ckeditor({ baseHref: "http://www.google.com/" }); }); </script> 

but does not work.

Some messages found using baseUrl and baseDir can solve the problem. I tried this:

  $('#editor1').ckeditor({ baseHref: "http://www.mydomain.com/", baseUrl: "http://www.mydomain.com/newsletter/", baseDir: "/newsletter/" }); 

but that didn't work either.

+6
source share
3 answers

I believe the problem is with the idea that ckeditor is mainly used for use on a web page. When you send all this via email, I think ckeditor is no longer tracking this baseHref for you.

If you find a way to add baseHref to this for each link before sending an email message (using any server language that you could use), it may be the result of what you want.

Something like this (pseudo code):

 // get ckeditor text // find/replace <a href=""></a> links with baseHref + link // mail result 
+3
source

According to ckeditor's documentation, it is like this:

{String} CKEDITOR.config.baseHref Starting at: 3.0 The base href URL used to resolve relative and absolute URLs in the contents of the editor. config.basehref = 'http://www.example.com/path/'; Default value: '' (empty string)

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html

0
source

baseUrl is the parameter you are looking for, but it is the CKFinder parameter that you must set on your server. It cannot be installed on javascript and, of course, not on a CKEditor instance.

0
source

Source: https://habr.com/ru/post/906813/


All Articles