Home: htmlArea 3 (beta): htmlArea 2 & 3 archive (read only): htmlArea v3.0 - Discussion:
IMG tags in HTMLArea use relative instead of absolute URLs



luisoliveira
New User

Jun 29, 2004, 1:08 PM


Views: 34560
IMG tags in HTMLArea use relative instead of absolute URLs

The scenario is the following: We have a CMS, in which we fitted in HTMLArea 3.0 RC1

The backoffice site is something like: backoffice.ourcompany.com

The frontend site is something like www.clientsite.com

In our backoffice, we always use absolute URLs to load images, so they can be acessible both by the frontend and by the backoffice. An example URL for a picture can be http://backoffice.ourcompany.com/pictures/xpto.jpg

The problem is, using HTMLArea, the absolute URL in the IMG tags gets converted to a relative URL, i.e., the HTML code referenced the images using pictures/xpto.jpg instead of using http://backoffice.ourcompany.com/pictures/xpto.jpg

This is a problem because when the page using HTMLArea generated HTML is viewed in the client's site, the images are downloaded from pictures/xpto.jpg, this directory doesn't exist in that frontend, hence the images won't load.

When we insert the images in HTMLArea, we always specify full URLs, but HTMLArea just chops them off and uses the relative URL instead.

Is there any way to force HTMLArea to always use absolute URLs for images?


novocaine
Novice

Jun 30, 2004, 4:10 AM


Views: 34541
Re: [luisoliveira] IMG tags in HTMLArea use relative instead of absolute URLs

I guess you're using IE. You'll have to look for occurances of stripBaseURL in htmlarea.js and simply comment them. Mozilla always makes full paths.

Hope that helps,
novocaine


luisoliveira
New User

Jul 1, 2004, 6:10 AM


Views: 34520
Re: [novocaine] IMG tags in HTMLArea use relative instead of absolute URLs

The problem occured in IE, just as you said.

Did exactly what you said (commented stripBaseURL occurances in htmlarea.js), and it works flawlessly, now absolute links to images are not chopped! Sly Thanks!

I just don't see the advantage of using stripBaseURL to begin with...


maevek
Novice

Aug 13, 2004, 12:24 PM


Views: 34271
Re: [novocaine] IMG tags in HTMLArea use relative instead of absolute URLs

How can I stop Mozilla from making full paths?
I'm trying to use relative URL's in htmlarea 3.
Thanks for any help...


bartclarkson
New User

Feb 14, 2005, 10:18 PM


Views: 33830
Re: [luisoliveira] IMG tags in HTMLArea use relative instead of absolute URLs

Like luisoliveira, I decided it was easier on the client if I devised a means of using insertHTML to place image tags into the HTMLArea based on a dynamic read of a directory of loaded images. The second some people have to deal with a path, their knees go wobbly, and you’ve lost them.

This business of cutting down to the relative path has not been thoroughly thought through. If you are seeing broken images, here is a more exact description of the fix. There are two areas to look at.

To get the URL to be ABSOLUTE in your TEXTAREA box, you have to make THIS change in the htmlarea.js:

FROM (circa line 2474):

Code
     
HTMLArea.prototype.stripBaseURL = function(string) {

var baseurl = this.config.baseURL;

// strip to last directory in case baseurl points to a file
baseurl = baseurl.replace(/[^\/]+$/, '');
var basere = new RegExp(baseurl);
string = string.replace(basere, "");

// strip host-part of URL which is added by MSIE to links relative to server root
baseurl = baseurl.replace(/^(https?:\/\/[^\/]+)(.*)$/, '$1');
basere = new RegExp(baseurl);
return string.replace(basere, "");

};



CHANGE TO THIS:

Code
     
HTMLArea.prototype.stripBaseURL = function(string) {
/*
var baseurl = this.config.baseURL;

// strip to last directory in case baseurl points to a file
baseurl = baseurl.replace(/[^\/]+$/, '');
var basere = new RegExp(baseurl);
string = string.replace(basere, "");

// strip host-part of URL which is added by MSIE to links relative to server root
baseurl = baseurl.replace(/^(https?:\/\/[^\/]+)(.*)$/, '$1');
basere = new RegExp(baseurl);
return string.replace(basere, "");
*/
return string;
};


Next fix, HTMLArea picture viewer also screws up path:

FROM (circa line 2409):


Code
                       // IE seems not willing to return the original values - it converts to absolute 
// links using a.nodeValue, a.value, a.stringValue, root.getAttribute("href")
// So we have to strip the baseurl manually :-/

if (HTMLArea.is_ie && (name == "href" || name == "src")) {
value = editor.stripBaseURL(value);
}




CHANGE TO THIS:


Code
                        // IE seems not willing to return the original values - it converts to absolute 
// links using a.nodeValue, a.value, a.stringValue, root.getAttribute("href")
// So we have to strip the baseurl manually :-/
/*
if (HTMLArea.is_ie && (name == "href" || name == "src")) {
value = editor.stripBaseURL(value);
}
*/


That should be close enough for rock 'n roll. Cool