Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#8805 closed bug (patchwelcome)

Internet Explorer changes link text when changing the href

Reported by: patrick@… Owned by: patrick@…
Priority: low Milestone: 1.next
Component: attributes Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

Description

Today I came across a IE bug and wanted to ask if we could apply a generic workaround to jquery. Here is the snipped which cases Internet Explorer to change the text when changing a href attribute:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
    <head>
        <title>Bug report</title>
        <script type="text/javascript" src="jquery-1.5.2.js"></script>
    </head>
    <body>
        <a href="#"> </a>
        <script type="text/javascript">
$(window).load(function() {
    $('a').text("www.example.org");
    $('a').attr("href", "http://www.example.com");
});
        </script>
    </body>
</html>

The text node should be www.example.org, but is "www.example.com".

My workaround: set the href first, then set the text node, but that is not a generic solution! generic workaround is explained at <a href="http://stackoverflow.com/questions/1790698">stackoverflow</a>. Temp. store the text node and restore it after setting the href attribute.

Change History (7)

comment:1 Changed 12 years ago by Timmy Willison

Owner: set to patrick@…
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsfiddle.net to help us assess your ticket. I'm not sure I understand what the problem is here.

comment:2 Changed 12 years ago by patrick@…

Status: pendingnew

Sorry, here is the jsFiddle.

Affected jQuery versions: 1.4.2 - 1.5.2
Affected Browser: Internet Explorer
Not affected Browser: Chrome, Safari, Firefox
Affected operating system: Windows
HowTo reproduce the issue: open jsFiddle in Internet Explorer
Expect to happen: result in jsFiddle should be

<a  id="testNode" href="http://www.example.com">www.example.org</a>

but in Internet Explorer it is:

<a id="testNode" href="http://www.example.com">http://www.example.com</a>

comment:3 Changed 12 years ago by Timmy Willison

Component: unfiledattributes
Priority: undecidedlow
Resolution: patchwelcome
Status: newclosed

Confirmed. I've looked into fixing this and I'm not sure it is worth the amount of code this requires. I tried setting the attribute every way I could think of and if I'm right, it would mean another test in support.js and at least 6-7 lines in attributes.js because it would mean a setter hook for href that temporarily saves out the anchors contents then reinserts them after setting the href.

IE changes the text only in certain cases. When setting the href to "www.jquery.com", I could reproduce the bug with the text set to "www.jquery.org", but not when set to "jquery". This is admittedly odd and frustrating behavior, but you probably don't want to set the text to .org when the href is going to .com. I suggest setting the text after the href for now and if someone can think of a way to add a fix for this without inflating the code too much, I think we would welcome a patch.

comment:4 Changed 12 years ago by patrick@…

small update:
Affected Browser: Internet Explorer <= 8
Not affected Browser: Chrome, Safari, Firefox, Internet Explorer = 9

comment:5 Changed 12 years ago by Timmy Willison

#9428 is a duplicate of this ticket.

comment:6 Changed 12 years ago by dmethvin

Disregard ...

Here is a fiddle showing the problem in pure DOM in IE:

http://jsfiddle.net/dmethvin/Rsv5J/

Last edited 12 years ago by dmethvin (previous) (diff)

comment:7 Changed 12 years ago by Timmy Willison

It seems it still has the same behavior when setting the property. This bug has been present since jQuery 1.0. I suggest setting the text after setting the href. The bug does not occur if text is not altered with javascript beforehand.

Note: See TracTickets for help on using tickets.