By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,609 Members | 3,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,609 IT Pros & Developers. It's quick & easy.

Javascript Lint error.

P: 40
i have to make a lint free java script file.
I'm almost done with all the changes. only one line is killing me.

[HTML]var newlnk = 'javascript:promptConfirmBox(\'' + ss[1] + '\', ' + newWindow + ')';[/HTML]

I'm getting a Script URL lint error in this line. Can some one tell me how to fix this or how to make the compiler ignore this.
Oct 21 '08 #1
Share this Question
Share on Google+
13 Replies


P: 40
I'm actually using this var to set attribute href to the <a> tag.
Oct 21 '08 #2

Expert 100+
P: 392
A semi colon in the string would not be a bad idea.



[HTML]var newlnk = 'javascript:promptConfirmBox(\'' + ss[1] + '\', ' + newWindow + ');';[/HTML]
Oct 21 '08 #3

rnd me
Expert 100+
P: 427
if you want to save some time, run your raw code though my compressor/formater before using lint.

it auto fixes things like semi-colons.

i have had files that had hundereds of lint errors, too many to continue.
after i ran it though my for matter, it was down to 8 errors, with just two click!


the app itself works in firefox only, but handles code for everyone.
the app is located here
Oct 21 '08 #4

P: 40
Putting a comma at the end does n't fix the error.
Please let me know if there is any other way to Fix this.
Oct 22 '08 #5

rnd me
Expert 100+
P: 427
lint is not perfect. frankly, it offers advice that could be considered opinion at best, dogma at worst. doug's treatment of eval and paren-less constructors comes to mind.

this is a perfect example. all the "error" means is that you are using javascript in as an A tag's href. this works fine in all browsers, but lint does not like it. There is nothing "wrong" with your code.

That said, i am not a huge fan of this pattern either. i would use a <span> instead of the <A> and move the href code into an onclick attrib. This cleans up the status bar and allows for more semantic documents.

if the script still works, i wouldn't lose any sleep over it. javascript code is not the structured markup of HTML. this makes it very difficult to "validate" javascript.
and since there is no standards on how to write javascript, a validator will reflect the whims of it's creator.
Oct 22 '08 #6

P: 40
thanks for the reply.

i have no other option other than to go for <a>.
My java script actually takes all the <a> tags and replaces its href with a prompt.

This is a prompt before moving to some other url.

Is there a way that i can suppress this error from the lint compiler. just make it ignore this error?
Oct 22 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Remove the "javascript:" protocol and set the onclick instead of the href attribute. The href should be set to a valid URL. To avoid going to that page too, add a return false at the end of the function.
Oct 22 '08 #8

P: 40
i found a interesting way to do that

var newlnk = /'javascript:promptConfirmBox/;
arr[i].setAttribute('href', newlnk.toString().substring(2, newlnk.toString().length - 1) + '(\'' + ss[1] + '\', ' + newWindow + ');');
Oct 22 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Interesting and very ugly too at that! What a hack just to get around a lint warning/error! As I said, remove the "javascript:" and set the onclick instead.
Oct 22 '08 #10

rnd me
Expert 100+
P: 427
grrr. i am starting to like lint even less.

when users are crapifying their code to jump though a lint hoop, it defeats the whole purpose.
in mu opinoion, this is worse than validation (something else i hate when people fret over).
it probably wont be long before we see button badges that say "Lint Me" right next to the also useless "Validate Me" button. Sometimes you need to validate, like when using XSLT or another processing method. but most of the time, validation only really solves "fake problems".

i've actually met someone who was literally embarrassed about his page not validating, so get this: he took it down. this was a departmental webpage and he put several users out for an afternoon because of a missing img tag alt attrib. Javascript could care less about that alt attrib...


I don't blame the OP, i blame doug for not qualifying lint's usage better.
Lint doesn't hurt my feelings, it offends my wisdom.


wait a second, what does this have to do with the question?
-hmm nothing i guess, but since i already typed my venting, i'll just click submit.
Oct 22 '08 #11

acoder
Expert Mod 15k+
P: 16,027
Sometimes you need to validate, like when using XSLT or another processing method. but most of the time, validation only really solves "fake problems".
Validation is important, not because it solves problems, but it provides a base to begin to solve problems. If your code's not valid in the first place, how can you expect browsers to display the markup properly and consistently? A missing alt attribute would be obvious from the validation errors. I don't for one minute suggest that a web page should be taken down because it doesn't validate, but it should be validated eventually and pages that are being written from scratch should definitely be validated and tested before being published.
Oct 23 '08 #12

rnd me
Expert 100+
P: 427
yup. that's what they say alright...

google uses quirks mode and it's not because they don't know what they are doing...

this is where programmers and page authors should agree to disagree.
Oct 23 '08 #13

acoder
Expert Mod 15k+
P: 16,027
Why can't someone be both? ;)

I'm not going to defend or criticise Google. Just one thing I will say is that most of the validation errors can be resolved in matter of minutes. However, if you've got a page which is not looking right and there's validation errors, you've got no room for complaints.
Oct 24 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.