I have a problem as follows: We're using a rich text editor (TinyMCE, but that's not important here, I think) in our application. Now, with Internet Explorer 8, we've noticed that if you type in content that looks like a web address:
www.google.com
...IE helpfully converts it to a link by some native-to-browser functionality. Now if you really want to make it into a link, and choose to edit link properties, and set the href e.g. to
www.google.com/analytics
...then when the javascript sets the href attribute of the anchor tag, also the text of the link changes. The desired result is:
`<a href="http://www.google.com/analytics">www.google.com</a>`
but actually is:
`<a href="http://www.google.com/analytics">www.google.com/analytics</a>`
Does anyone know a way to work around this?
Update: This behavior has only been observed in Internet Explorer 8 and 7. Firefox, Chrome, and Safari are not affected. The problem can also be observed on the TinyMCE websitehttp://tinymce.moxiecode.com/examples/full.php, so it's probably not a TinyMCE configuration issue.
Need more information:
After some research and debugging, I found that the problem is caused by built-in behavior of Internet Explorer. It occurs when setting the href-property of a link, whose text-content appears to be an URL (according to IE). In these cases, IE copies the contents of the
href
-attribute into the link text.There might be several workarounds for this, but I found that at least this logic works:
innerHTML
into a temporary variable,href
attribute as usualinnerHTML
has changed, copy back the originalinnerHTML
from the temporary variable.This seems to work because changing the
innerHTML
of the link does not cause changing of thehref
attribute.In tinyMCE, find the following line in setAllAttribs() of functions.js of the advlink plugin:
...and replace it with this monster:
...and your links will appear as if untouched. I also started a thread on the tinyMCE forums about this. If they post some improvements to my solution or tell it's nonsense, I'll update this question also.