Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use absolute URLs while saving image sources in Database from CKEDITOR

I am using CKEDITOR for creating newsletters. Everything went fine but when I send newsletters to email, the images stored there aren't displayed. The problem was caused by CKEDITOR using relative path for image sources, e.g. <img src='/newsletter_images/news1/img1.jpg'>.

I want CKEDITOR to use absolute urls such as:

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

The initialization I tried is as follows:

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

but didn't work.

On some posts I found using baseUrl and baseDir could solve the issue. I tried this:

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

but that didn't work either.

like image 585
Prajwal Avatar asked Jan 25 '12 03:01

Prajwal


1 Answers

I believe the problem has to do with the idea that the ckeditor is mainly for webpage-based use. When you are sending all this in an email, I would think the ckeditor no longer keeps track of that baseHref for you.

If you found a way to add on that baseHref to each link before the email is sent out (using whatever server-side language you might be using,) it might end up with the result that you want.

Something like this (pseudocode):

// get ckeditor text
// find/replace <a href=""></a> links with baseHref + link
// mail result
like image 179
summea Avatar answered Oct 12 '22 22:10

summea