Project

General

Profile

Actions

Feature #1348

closed

Render empty WAnchors as <a>, not <span>

Added by Jake Petroules almost 12 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
07/03/2012
Due date:
% Done:

0%

Estimated time:

Description

The fact that Wt renders WAnchors with empty WLinks as s instead of s causes CSS problems with projects like Bootstrap whose CSS selectors specifically require s. Could there perhaps be a setting (or simply a behavior change) so that empty links are always rendered as tags? All versions of the HTML specification have never required an href attribute on , so this should not be a problem; see http://dev.w3.org/html5/spec/single-page.html#the-a-element

  • If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant.
  • The target, rel, media, hreflang, and type attributes must be omitted if the href attribute is not present.

Files

a-span-patch.diff (1.5 KB) a-span-patch.diff Jake Petroules, 07/04/2012 07:14 PM
a-span-patch.diff (1.7 KB) a-span-patch.diff Jake Petroules, 07/10/2012 09:03 AM
Actions #1

Updated by Koen Deforche almost 12 years ago

  • Status changed from New to InProgress
  • Assignee set to Koen Deforche

Hey Jake,

I don't exactly recall what was the problem with an anchor without href, but there issues. But perhaps only with older (mobile) browsers.

I'ld be happy to revisit this indeed, since it is an annoyance.

Regards,

koen

Actions #2

Updated by Jake Petroules almost 12 years ago

Yeah, I have also read that iOS devices require href="#" for certain things (the Twitter Bootstrap team has taken note of this), but that can easily be worked around by the user (using WLink("#") or custom JavaScript), and it seems that substituting span wouldn't really help the issue anyways.

I started working on this but Wt still renders an href attribute with no value, i.e. <a href>Link</a>, which causes the browser to substitute the current URL for href's value. It needs to be completely omitted. I don't know if that requires some JavaScript changes to ensure that the attribute name is completely removed, not just emptied. Anyways I've attached a patch of what I did so far. Cheers!

Actions #3

Updated by Koen Deforche almost 12 years ago

  • Status changed from InProgress to Feedback

Hey,

I tried your patch. All you are missing is : needsUrlResolution = false, because otherwise the href is set client-side.

I'ld be interested in hearing if you hit any adverse problems ? The '#' trick is somewhat problematic on older browsers (IE6 - IE9) since it might interfere with the internal path handling using URL fragments.

Regards,

koen

Actions #4

Updated by Jake Petroules almost 12 years ago

Hey Koen,

If the WAnchor has a null WLink, it can simply render without an href attribute at all, which should not have any problems at all in the first place and it is valid for an tag to lack an href attribute. That part I think we are in agreement with? The only thing to be careful about is to make sure that empty href attributes cannot be set, i.e.:

<a>Link</a> // OK
<a href>Link</a> // Problem
<a href="">Link</a> // Problem
<a href="/items">Link</a> // OK

Now the second part of this topic and the only actual issue as far as I am aware, is that some links require href="#" to work properly in certain situations and environments as I noted above.

I believe I have a solution but first I need to ask: is '#' by itself an invalid internal path (you need at least #/ I think)? If that is true, we could check if the WAnchor's WLink is comprised solely of #, then its click event could be set to call e.preventDefault() so the browser won't react to a navigation event and mess up internal paths (but should still be able to participate in Wt event handling).

What are your thoughts on this approach? I will also do more testing later today with needsUrlResolution = false as you noted.

Actions #5

Updated by Koen Deforche almost 12 years ago

Hey Jake,

Setting needsUrlResolution to false will make this work.

As to the '#' problem, we should first find out if it is actually Internet Explorer which would require the href attribute in the first place, otherwise it is effectively not a problem.

Regards,

koen

Actions #6

Updated by Jake Petroules almost 12 years ago

Does the following look right to you?

needsUrlResolution = link_.isNull() ? false : (!app->environment().hashInternalPaths() && href.find("://") == std::string::npos && href[0] != '/');
Actions #7

Updated by Jake Petroules almost 12 years ago

Koen, please take a look at this: http://stackoverflow.com/a/11404263/343845

Also, do note that there IS a difference between href and href="". From everything I've looked into in the past couple of days I can't find anything that would appear to indicate that the lack of an href attribute is a problem. I've attached my updated patch that accounts for needsUrlResolution; please let me know if we can proceed with this.

Also I think we still need a solution to href="#" since I expect it will interfere with internal paths. I will test this later.

Actions #8

Updated by Koen Deforche almost 12 years ago

Hey Jake,

That looks correct (although I will refactor things a bit since link_.isNull() really is a different code path)

I've looked it up: this is a change since August last year, but I cannot trace any reasoning for it. So I am inclined to accept the proposal to drop the workaround (after the final Wt 3.2.2 release).

Regards,

koen

Actions #9

Updated by Koen Deforche over 11 years ago

  • Status changed from Feedback to Resolved
  • Target version set to 3.2.2-p1
Actions #10

Updated by Koen Deforche over 11 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF