Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSHint marks "javascript:void(0);" as a JS URL #1738

Closed
strugee opened this issue Jun 23, 2014 · 8 comments
Closed

JSHint marks "javascript:void(0);" as a JS URL #1738

strugee opened this issue Jun 23, 2014 · 8 comments

Comments

@strugee
Copy link

strugee commented Jun 23, 2014

If I assign an element's href to javascript:void(0); (as opposed to #), like so:

$('#foobar').attr("href", "javascript:void(0);");

JSHint picks up the javascript:void(0); construct as a Script URL:

PS C:\Users\hal9000\Development\strugee.github.com> grunt lint
Running "jshint:all" (jshint) task

   js\main.js
     30 |    $('#lightbulb-icon').attr("href", "javascript:void(0);");
                                                                    ^ Script URL.

>> 1 error in 4 files

when in fact it isn't doing anything and is semantically valid. There should be an exception for these types of Script URLs.

@strugee
Copy link
Author

strugee commented Jun 23, 2014

Nevermind.

Perhaps this should be a specialized warning? I can't be the only one to have been confused by this.

@valueof valueof closed this as completed Jul 6, 2014
@weeger
Copy link

weeger commented Aug 13, 2014

You're not.

@kcampion
Copy link

kcampion commented Sep 9, 2014

Just put this line at the top of your file to disable the warning:

/*jshint scripturl:true*/

But the best way is to use "#" into the href and to return "false" for all javascript events:

<a href="#" onclick="doSomething();return false;">my link</a>

@rwaldron
Copy link
Member

rwaldron commented Sep 9, 2014

No, the best way is to keep your JavaScript out of your markup and attributes :P

@kcampion
Copy link

kcampion commented Sep 9, 2014

@rwaldron: rectification, indeed

$('#foobar').attr("href", "#").click(function() {
  // do it
});

@MikeGodin
Copy link

Passes jslint:
$('#foobar').attr('href','javascript'+String.fromCharCode(58)+'void(0);');

@strugee
Copy link
Author

strugee commented Aug 4, 2016

@MikeGodin looks like a separate bug.

@englishextra
Copy link

@kcampion putting # and return false is not always desirebale
in my case i dont want hash to appear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants