Javascript Lint error.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sreemathy2000
    New Member
    • Oct 2007
    • 40

    Javascript Lint error.

    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:pro mptConfirmBox(\ '' + 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.
  • sreemathy2000
    New Member
    • Oct 2007
    • 40

    #2
    I'm actually using this var to set attribute href to the <a> tag.

    Comment

    • pronerd
      Recognized Expert Contributor
      • Nov 2006
      • 392

      #3
      A semi colon in the string would not be a bad idea.



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

      Comment

      • rnd me
        Recognized Expert Contributor
        • Jun 2007
        • 427

        #4
        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

        Comment

        • sreemathy2000
          New Member
          • Oct 2007
          • 40

          #5
          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.

          Comment

          • rnd me
            Recognized Expert Contributor
            • Jun 2007
            • 427

            #6
            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.

            Comment

            • sreemathy2000
              New Member
              • Oct 2007
              • 40

              #7
              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?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                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.

                Comment

                • sreemathy2000
                  New Member
                  • Oct 2007
                  • 40

                  #9
                  i found a interesting way to do that

                  var newlnk = /'javascript:pro mptConfirmBox/;
                  arr[i].setAttribute(' href', newlnk.toString ().substring(2, newlnk.toString ().length - 1) + '(\'' + ss[1] + '\', ' + newWindow + ');');

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    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.

                    Comment

                    • rnd me
                      Recognized Expert Contributor
                      • Jun 2007
                      • 427

                      #11
                      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.

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by rnd me
                        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.

                        Comment

                        • rnd me
                          Recognized Expert Contributor
                          • Jun 2007
                          • 427

                          #13
                          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.

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            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.

                            Comment

                            Working...