Link to javascript functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blackmore
    New Member
    • Mar 2007
    • 25

    Link to javascript functions

    I'd like to screate a link to my javascript functions, such that they do not appear in the page source code and users cannot tamper with them. I've noticed that other websites appear to be able to this usings commands such as:

    [HTML]<SCRIPT src="folder/functions.js" type=text/javascript></SCRIPT>[/HTML]

    However, when I try this it does not work. Can anyone explain what I need to do to make this work OR point me in the direction of a suitable tutorial to explain the issue.

    Blackmore
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    This is a subject that is visited many, many times.

    In short: you cannot effectively *hide* the JavaScript because it has to be readable by the browser - and the browser can only *see* what a human can.

    What you've displayed in your post is that of external javascript, that is, a javascript file that is linked to from the file.

    Here is a tutorial on that.

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      i think you mean an external script tag .

      edit- whoops, need a taller monitor; already answered.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by Blackmore
        I'd like to screate a link to my javascript functions, such that they do not appear in the page source code and users cannot tamper with them. I've noticed that other websites appear to be able to this usings commands such as:

        [HTML]<SCRIPT src="folder/functions.js" type=text/javascript></SCRIPT>[/HTML]

        However, when I try this it does not work. Can anyone explain what I need to do to make this work OR point me in the direction of a suitable tutorial to explain the issue.
        Perhaps it's because the type attribute needs to be quoted:
        [HTML]<script src="folder/functions.js" type="text/javascript"></script>[/HTML]
        When you say it doesn't work, what do you mean? As explained above, you can't hide JavaScript source code. Sure, for someone who doesn't know any better, using external JS files will fool them, but there's a lot more savvy users out there. What are you worried about specifically when you mention "tampering" ?

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by markusn00b
          Here is a tutorial on that.
          That may be the first result on Google, but it's out of date. The Browser Compatibility notice at the top might've given a clue: NS4 and IE4 (eugh!). The only things wrong are that it uses the deprecated language attribute, uses capital letters (though that shouldn't be a problem in plain HTML), and uses the "javascript :" protocol in a link href. Thought I'd just point out :)

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by acoder
            That may be the first result on Google, but it's out of date. The Browser Compatibility notice at the top might've given a clue: NS4 and IE4 (eugh!). The only things wrong are that it uses the deprecated language attribute, uses capital letters (though that shouldn't be a problem in plain HTML), and uses the "javascript :" protocol in a link href. Thought I'd just point out :)
            My apologies
            :)

            It was late!

            I wasn't aware there was anything wrong with using 'javascript: function()' in a href attribute?

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              No problem. You want reasons, you got them.

              Comment

              Working...