RESOLVED FIXED Bug 17714
anchor elements href="#" and "name" attribute cause the page to jump to the end
https://bugs.webkit.org/show_bug.cgi?id=17714
Summary anchor elements href="#" and "name" attribute cause the page to jump to the end
jasneet
Reported 2008-03-07 16:03:32 PST
I Steps: Go to the attached reduction. Click on "Click me" II Issue: Notice that on clicking "Click me", the page jumps to the end. This happens only in Safari III Conclusion: combination of href="#" and name="" is causing the issue. IV Other browsers: IE7: ok FF: ok Opera: ok V Nightly tested: 30236
Attachments
reduction (243 bytes, text/html)
2008-03-07 16:05 PST, jasneet
no flags
The patch for this bug. (3.55 KB, patch)
2008-03-11 06:01 PDT, Yuzhu Shen
darin: review+
jasneet
Comment 1 2008-03-07 16:05:07 PST
Created attachment 19597 [details] reduction
Robert Blaut
Comment 2 2008-03-08 14:24:42 PST
Confirmed.
Yuzhu Shen
Comment 3 2008-03-11 05:55:53 PDT
This issue is similar with bug 14867. Because of revision 30243, however, bug 14867 is ok now. In revision 30243, FrameLoader::gotoAnchor() is modified: DeprecatedString ref = m_URL.encodedHtmlRef(); --> String ref = m_URL.ref(); With this change, WebKit now interprets the fragment identifier of <a href="#"> as an empty string (length = 0) instead of a null string. As I commented in bug 14867, WebKit searches the anchor node in two steps: (in bool FrameLoader::gotoAnchor(const String& name)) 1) searches any node whose id attribute is the same as the fragment identifier. If the fragment identifier is an empty string, it returns directly. 2) searches in a set of <a> elements that have name attributes, using HTMLCollection::namedItem(). It should be noted that namedItem() first searches for an object with a matching id attribute. If a match is not found, the method then searches for an object with a matching name attribute. Consider the following node: <a name="">...</a> Its id attribute is not specified (returned as a null string when querying it), so it won't match. However, if we are searching with a empty string, it will match the name attribute. As a result, clicking the "Goto Top" link in the page below will bring you to the anchor "Oops!" but not the top of the page. ======================================= ... <a href="#">Goto Top</a> ... ... <a name="">Oops!</a> ... =======================================
Yuzhu Shen
Comment 4 2008-03-11 06:01:36 PDT
Created attachment 19660 [details] The patch for this bug.
Darin Adler
Comment 5 2008-03-11 07:43:56 PDT
Comment on attachment 19660 [details] The patch for this bug. r=me
Darin Adler
Comment 6 2008-03-16 13:35:47 PDT
Committed revision 31083.
Note You need to log in before you can comment on or make changes to this bug.