TinyMCE: absolute / relative URL’s

These are the different configuration scenarios for URLs within TinyMCE

  1. Relative URL’s
  2. Absolute URL’s
  3. Domain Absolute URL’s
  4. No URL Conversion

Document_base_url

This option specifies the base URL for all relative URLs in the document. The default value is the directory of the current document. If a value is provided, it must specify a directory and must end with a “/”. This option also interacts with the relative_urls, remove_script_host, and convert_urls options to determine whether TinyMCE returns relative or absolute URLs.

Changed in 3.0: This may affect how other paths are interpreted, such as calls to tinyMCE.windowManager.open, so you may want to use absolute paths. The following configuration settings also appear to be affected by the document_base_url setting:

  • external_link_list_url
  • external_image_list_url

Relative URL’s

This will convert all URL’ss within the same domain to relative URLs. The URLs will be relative from the document_base_url.

relative_urls : true,
document_base_url : "http://www.site.com/path1/"

Example: http://www.site.com/path1/path2/file.htm >> path2/file.htm

Absolute URL’s

This will convert all relative URLs to absolute URLs. The URLs will be absolute based on the document_base_url.

relative_urls : false,
remove_script_host : true,
document_base_url : "http://www.site.com/path1/"

Example: path2/file.htm >> /path1/path2/file.htm

Domain Absolute URL’s

This will convert all relative URLs to absolute URLs. The URLs will be absolute based on the document_base_url with domain.

relative_urls : false,
remove_script_host : false,
document_base_url : "http://www.site.com/path1/"

Example: path2/file.htm >> http://www.site.com/path1/path2/file.htm

No URL Conversion

convert_urls : false

Example: path2/file.htm or http://www.site.com/path1/path2/file.htm will not be converted at all.

Note: Some versions of Internet Explorer may continue to convert URL’s even with convert_urls set to false. Consider using the valid_elements initialization option and excluding the a (anchor) tag. Here’s a working workaround, needing the paste plugin. In your TinyMCE init config, add:

paste_preprocess : function(pl, o) {
    // Strip <a> HTML tags from clipboard content (Happens on Internet Explorer) 
    o.content = o.content.replace( /(\s[a-z]+=")]+&gt;([^/gi, '$1$2' ); }

Leave a Reply