Absolute and Relative Paths in MSHTML

After reading of issues that MSHTML (or the DEC, the DHTML Editing Component) has with setting all paths to absolute, I felt I should divulge my solution: set the baseurl of the editor.

If using the DEC, where editor is the id of the object try the following:

editor.BaseURL = "http://www.example.com/";

In doing so, any calls to an href should now omit the base URL.

Published January 31, 2006 · Updated September 14, 2006
Categorized as MSHTML and DEC
Short URL: https://snook.ca/s/516

Conversation

3 Comments · RSS feed
Jeroen said on March 18, 2006

I only use MSHTML (can't use active x components), and I couldn't get it to work. First, I think you mean the BaseHref property (instead of BaseURL).

If I create a link, then go to source code view, and then go back to wysiwyg mode, the relative links are still made absolute (using the base href).
Take a look at this:
http://www.netq.nl/mshtml
There is a relative link in the editable div. Click on copy to source code, it looks ok. Now click on copy to editable div. Now the link are made absolute as you can see when you click again on copy to source code.

Jonathan Snook said on March 18, 2006

Ah, yes. It seems you're right. In looking over my code, I can see that even with the DEC there were times that I had to strip out the base URL using something like this:

var tmphref = el.href;
if (tmphref.lastIndexOf(baseURL) != -1)
  tmphref = tmphref.substr(baseURL.length); 
said on August 22, 2006

fvdvxc

Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.