Disabling auto-linking in an IE rich text editor

by Jason on June 17, 2011 · 7 comments

I just answered this on Stack Overflow, so I thought I’d share: when you use a rich text editor in a web page, such as nicEdit, if you type a URL or an email address into the text box in IE, it’ll automatically turn it into a link.  On Firefox, it doesn’t.  So what’s the deal, and can you turn it off?

tl;dr: It’s a Microsoft design decision, but as of IE9 you can disable it through javascript.

Here’s the setup: Windows-based browsers instantiate a MSHTML rich text editor to do their rich text stuff.  There’s a setting in there, called IDM_AUTOURLDETECT_MODE that determines if  URL auto-linking is on or off.  It’s an ActiveX control, so if you’re putting it into a desktop app, you can use IOleCommandTarget::Exec and set it to whatever you want.  If you’re building a web page, however, you’re out of luck, or at least you used to be.

There are some settings that you can tweak through Javascript, but until recently this wasn’t one of them.  The document.execCommand takes a string parameter to specify the command you’re accessing, but there wasn’t a mapping in the back end to turn that into a value that the editor knew what to do with.

As of IE9, Microsoft has enabled a mapping for this called AutoUrlDetect, so now, if you’re lucky enough to have an IE user visit with IE9, you can call document.execCommand(“AutoUrlDetect”, false, false) and autolinking will be disabled.

For other versions of IE, life continues to suck.  There aren’t any really good ways I can see to get around this without nuking all links in the text box, some of which might have been legitimately placed there.

In the grand scheme of things, it’s a minor annoyance, but one that I’m glad there’s a fix for as well as documentation around.  There’s always something that a client will notice happening in one browser and not others, and for whatever reason this might be flagged as a show stopper in your project, because of course you can do anything if you put your mind to it, right?  At least now the problem is known and is on the (slow) way out, and Microsoft has info on the original problem and the fix in case my word isn’t good enough :)

Oh, and in case you want to go the other way: if you try the opposite of that code in Firefox on a machine with IE9 installed (so document.execCommand(“AutoUrlDetect”, false, true);), it doesn’t seem to work, which is probably just as well, since I’ve no idea what the equivalent would be on non-Windows machines.  All in all, this seems like the kind of thing that javascript should control.

{ 7 comments… read them below or add one }

Brendan March 22, 2013 at 10:19 am

Thanks for the info, this was a big help! I had a solution that was as you said nuking all the links and then adding them back in the expected non-link form but there was a slight delay and it looked kind of hackish. This works much better

SOURCE April 28, 2013 at 9:34 pm

Howdy! I could have sworn I’ve been to this website before but after checking through some of the post I realized it’s new to me.
Anyways, I’m definitely delighted I found it and I’ll be book-marking and
checking back frequently!

resimler May 7, 2013 at 12:47 am

If your tween is into paint-ball you can take everyone to play paint-ball.

At the end of the party all of the papers write down who they think was the
prohibition agent. You Divide everyone at the party into two groups, or tribes.

Dalene June 5, 2013 at 10:43 pm

Loving the info with this site, you’ve done great job inside the blog posts.

free shipping cheap Rockets jerseys June 5, 2014 at 10:03 am

cheap Cavaliers jerseys free shipping for sale from china

professional bodybuilder workouts June 11, 2014 at 9:07 am

Marvelous, աhat a eblog itt is! Thhis weblog presents valuable facts to us,
ҝeep it up.

www.przystajn.eu June 19, 2014 at 10:40 am

Hello there I am so grateful I found your weblog, I really found you by error, while I was researching on Digg for something else,
Anyways I am here now and would just like to say kudos for a remarkable
post and a all round enjoyable blog (I also love the theme/design), I don’t have time to browse it all at the moment but I have saved it and
also included your RSS feeds, so when I have time I will be back to read more, Please do
keep up the awesome work.

Leave a Comment

Previous post:

Next post: