Javascript: Workaround: Internet Explorer changes link text when href changes

I have a problem: we use a text file editor (TinyMCE, but it doesn’t matter here, I think) in our application. Now, using Internet Explorer 8, we noticed that if you enter content that looks like a web address:

www.google.com

... IE helps convert it to a link using some of the built-in browser features. Now, if you really want to make this a link, and select edit link properties and set href, for example. before

www.google.com/analytics

... then when javascript sets the href attribute of the anchored tag, the link text also changes. Desired Result:

`<a href="http://www.google.com/analytics">www.google.com</a>`

but actually:

`<a href="http://www.google.com/analytics">www.google.com/analytics</a>`

Does anyone know a way around this?

. Internet Explorer 8 7. Firefox, Chrome Safari . - TinyMCE http://tinymce.moxiecode.com/examples/full.php, , , TinyMCE.

+5
2

, Internet Explorer. href- , URL- ( IE). IE href .

, , :

  • innerHTML ,
  • href
  • innerHTML , innerHTML .

, innerHTML href.

tinyMCE setAllAttribs() .js advlink:

setAttrib(elm, 'href', href);

... :

if(tinyMCE.isMSIE) {
    var tmp = elm.innerHTML;
    setAttrib(elm, 'href', href);
    if(elm.innerHTML != tmp) // optional, but keeps unnecessary innerHTML set:s away
        elm.innerHTML = tmp;
}
else {
    setAttrib(elm, 'href', href);
}

... . tinyMCE . , .

+8

:

  • ?
  • html?
  • TinyMCE? - HTML- .
0