Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-1084

Links should not target "#" or "javascript:void(0)"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Replace this 'href' value by a link to an existing page or anchor.
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Legacy Key:
      LinkToNothingCheck
    • Covered Languages:
      HTML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min

      Description

      There are two ways to build a link that has the sole purpose of running JavaScript code. The goal of this rule is to ban such patterns in order to support browsing with JavaScript disabled.

      Noncompliant Code Example

      <a href="#" onclick="alert('Clicked!'); return false;">Run JavaScript Code</a> <!-- Noncompliant -->
      <a href="javascript:void(0)" onclick="alert('Clicked!'); return false;">Run JavaScript Code</a>  <!-- Noncompliant -->
      <a id="inPageAnchor">Jump down the page to me</a>  <!-- Compliant -->
      

      Compliant Solution

      <a id="inPageAnchor">Jump down the page to me</a>  <!-- Compliant -->
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            freddy.mallet Freddy Mallet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: