rspec/rules/S1084/html/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

55 lines
1.4 KiB
Plaintext

== Why is this an issue?
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
[source,html]
----
<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
[source,html]
----
<a id="inPageAnchor">Jump down the page to me</a> <!-- Compliant -->
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace this 'href' value by a link to an existing page or anchor.
'''
== Comments And Links
(visible only on this page)
=== on 19 Jun 2013, 09:16:25 Dinesh Bolkensteyn wrote:
It seems that there is a difference between the 2 patterns.
* # will scroll back up to the top of the page.
* javascript:void(0) does not affect the scrollbar.
But indeed with the return false; in the onclick, both do the same.
=== on 19 Jun 2013, 09:48:12 Dinesh Bolkensteyn wrote:
I'm wondering if this rule should also apply to href="" or not.
=== on 8 Jul 2013, 18:25:37 Freddy Mallet wrote:
Is implemented by \http://jira.codehaus.org/browse/SONARPLUGINS-2984
endif::env-github,rspecator-view[]