Today is . Page created 04/10/06 updated 08/31/09

Traditional Traditional Copy & Paste ~ No .js File Copy and Paste Cut and Paste

More and more we see the transition to make javascripts into external javascripts (.js files) as opposed to the older, more traditional copy/cut and paste directly into the document. Not everyone is comfortable with this and if you go to the script site(s) this is what you are seeing more and more.

<!-- Paste this code into an external JavaScript file named: whatever.js -->

We can go on and on about the advantages of using the external .js scripts as opposed to the traditional way but lets face it, if you are not comfortable doing it, then don't. Below, we will show you howto still copy/cut and paste the script earmarked for an external .js script directly into your document as you have been accustomed to doing for however long.

The problem is that the script that is earmarked to be an external .js script is not complete on its face to add directly into the document and must be finished. See the "Unfinished"* below example:

*     When we say "Unfinished", we mean it in the sense that it does not have an opening and closing javascript code to signify it as a javascript. By pasting the below directly into a webpage, the result you would get is to see the below code appear on the page as basic text, nothing else. Grab the below link to see what it would look like to paste the below as is directly into the webpage in the designated location.
Unfinished Example On Webpage ]
Unfinished Code

<!-- Paste this code into an external JavaScript file named: whatever.js -->

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Philip Myers :: http://virtualipod.tripod.com/bookmark.html */

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt
(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

To "Finish" the above "Unfinished" script so you can add it directly into your document and not use it as an external .js script, you need to add the following two little bits of code in the appropriate places .

<SCRIPT LANGUAGE="JavaScript">

// End -->
</script>

Finished Code

<!-- Paste this code into an external JavaScript file named: whatever.js -->

<SCRIPT LANGUAGE="JavaScript">

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Philip Myers :: http://virtualipod.tripod.com/bookmark.html */

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt
(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

//  End -->
</script>

Notice where we added the opening and closing javascript tags in the above "Finished" example. By doing this you can now add that portion of script directly into your webpage in the traditional way instead of making it into an external .js file and upload it to your directory. You can also remove the below part of the code because all it is doing is giving instruction on what to do with that section of code.

<!-- Paste this code into an external JavaScript file named: whatever.js -->

Since you are not going to use the external .js script, then the next part of the code from the script site is null and void. In other words, you do not need it.

<!-- Paste this code into the <HEAD> section of your HTML document.
You may need to change the path of the file. -->

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

Instead of using and calling the above .js code, you would now be able to copy/cut and paste the section (where designated) of code you added the finishing little bits of code to so it is now designated as a javascript and not an external .js file.

The above code we used for our example of "Finished" and "Unfinished" comes from "The JavaScript Source". The script we used is for a Bookmark Page Script ]. that calls for the use of an external .js file.

To emphasize the point that you can use either the external .js file or the traditional copy/cut and paste directly into your document, we have built examples of both methods using the "Bookmark Page Script".
Example With .js File ] [ Example Without .js File ]

We hope our tutorial was easy to follow and we covered everything in detail. If you would like to add this effect into your pages, grab the respective below link and you are there. If you have any problems with this or anything else, feel free to consult our FAQ ] and if you can't find the answer there, contact us ].
Get Code Here ]   [ Rate This Page ]   Scripts In Conflict ]   Bookmark and Share