htmlArea

A directory of browser-based WYSIWYG editors

  MAIN
INDEX
SEARCH
POSTS
WHO'S
ONLINE
LOG
IN

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


The htmlArea 2 & 3 editors have been discontinued.

We've made these forums available as a read-only reference and knowledge-base for people using or developing editors based on htmlArea 2 or 3.

Anyone who is interested in taking over version 2 or 3 is free to do so. All we ask is that you choose a new name that doesn't have "htmlarea" in it to avoid confusion with this site. We'll even give you a link in the directory to make it easier for people to find you. If you are developing or hosting an htmlArea based-editor under a new name, please submit it to our directory.

 


luisoliveira
New User

Jun 29, 2004, 1:08 PM

Post #1 of 5 (35563 views)
Shortcut
IMG tags in HTMLArea use relative instead of absolute URLs Can't Post

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

Post #2 of 5 (35544 views)
Shortcut
Re: [luisoliveira] IMG tags in HTMLArea use relative instead of absolute URLs [In reply to] Can't Post

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

Post #3 of 5 (35523 views)
Shortcut
Re: [novocaine] IMG tags in HTMLArea use relative instead of absolute URLs [In reply to] Can't Post

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

Post #4 of 5 (35274 views)
Shortcut
Re: [novocaine] IMG tags in HTMLArea use relative instead of absolute URLs [In reply to] Can't Post

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

Post #5 of 5 (34833 views)
Shortcut
Re: [luisoliveira] IMG tags in HTMLArea use relative instead of absolute URLs [In reply to] Can't Post

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

 
 
 


Search for (options)