How to Hide Java Script Code

Some webmasters place JavaScript code directly in the HTML pages. Placing it in the pages makes it convenient to add and edit, but the code can be seen by search engines and readers who open the page code. To hide the JavaScript from the reader, you place it in a separate file, give it the "JS" file extension and then link to it in your HTML code.

Instructions

    • 1

      Right-click the HTML page that contains the open JavScript code. Select "Open With," and then double-click your HTML editor to load the code.

    • 2

      Highlight all of the JavaScript code within the opening "<script>" tag and closing "<script>" tag. Right-click the highlighted code, and select "Cut." The JavaScript is removed from the page and copied to the Windows clipboard.

    • 3

      Click the Windows "Start" button, and type "notepad" in the search text box. Press "Enter" to open the editor. Right-click the new file in the editor, and select "Paste." Your JavaScript code pastes into the file.

    • 4

      Press "Ctrl" and "S" keys to open the "Save" dialog box. Name the file "javascript.js," and press "Enter." Your JavaScript code is stored in an external file, but you must link to the new file for it to run in the HTML page.

    • 5

      Return to the opened HTML Web page. Type the following code to link the JavaScript file:

      <script type="text/javascript" src="javascript.js"></script>

Tips & Warnings

  • After you edit the code, you must upload the new HTML file and the external JS file to your Web host directory.

Related Searches:

References

Comments

Related Ads

Featured