DK-Flag Erik Østergaard - Source code snippets / Kildekode småstykker Go to Home Page
 (Geometric Shapes) Source code snippets Return
  
  
Bottom of This Page

 

JavaScript

- source code snippets /
- kildekode småstykker

Education

 


(Geometric Shapes) JavaScript (JScript) source code snippets JavaScript (JScript) source code snippets / JavaScript (JScript) kildekode småstykker

- JScript is Microsoft's implementation of JavaScript. / - JScript er Microsofts udførelse af JavaScript.

Warning Warning / AdvarselWarning: Don't run the script files without reading them first! /
Warning / AdvarselAdvarsel: Kør ikke script-filerne uden at læse dem først!

JavaScript - source code snippets / JavaScript - kildekode småstykker

Update your HTML (HyperText Markup Language) Copyright (c) date automatically using JavaScript / Opdater din HTML (HyperText Markup Language) Copyright (c) dato automatisk ved at bruge JavaScript

Description: This script allows you to update your copyright date automatically by showing a copyright line, that automatically stays updated and forever stay updated with the current year. / Beskrivelse: Dette skript giver dig mulighed for at opdatere din ophavsret-dato automatisk ved at vise en copyright-linje, som automatisk forbliver opdateret og altid holder sig opdateret med det indeværende år.

Overview - Function(s)... / Oversigt - Funktion(er)...

Developed and tested under browser(s): Microsoft Internet Explorer Version 8.x. / Udviklet og testet under browser(e): Microsoft Internet Explorer Version 8.x.

1a Implementation: (How to use:) Insert this code in the <HEAD></HEAD> section of your HTML (HyperText Markup Language) document. /
1a Implementering: (Sådan bruger du:) Indsæt denne kode i <HEAD></HEAD> sektionen af dit HTML (HyperText Markup Language) dokument.



<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript Applet and hide from old browsers -----

function copyrightDateString(copyYear) {
  // Returns the year part in a copyright notice as a string.
  //
  // Description: This script allows you to update your copyright date 
  // automatically by showing a copyright line, that automatically stays 
  // updated and forever stay updated with the current year.
  //
  // Syntax:
  //  'copyYear': the start copy year integer (four digits).
  //
  // A HTML page 'JavaScript' example of how to use it:
  //  Just place this code in your HTML document where you want the 
  //  year part in a copyright notice to appear and voila, your year 
  //  part in your copyright notice will update automatically for 
  //  years to come.
  //  Remove the two slashes (//) from the start of the code lines 
  //  and the square brackets ([) (]) from the code example below 
  //  before trying it.
  // * * *
  // [<]P ALIGN="left"[>]
  // [<]SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"[>]
  // [<]!-- Beginning of JavaScript Applet and hide from old browsers -----
  //
  // var htmlCopyrightLine = "" + "&copy;" + copyrightDateString('1997') + " by Me, all rights reserved.";  // Force number to a string.
  //
  // document.open();
  // document.write( htmlCopyrightLine );
  // document.close();
  //
  // // - End of JavaScript code and done hiding --[>]
  // [<]/SCRIPT[>]
  // [<]/P[>]
  // [<]noscript[>]
  // [<]P ALIGN="left"[>]
  // &copy;1997 - 2012 by Me, all rights reserved.
  // [<]/P[>]
  // [<]/noscript[>]
  // * * *
  // Return string:
  //  If this year is 1997 and the value passed to this function is '1997', 
  //  it will say "1997". Next year, it will say "1997 - 1998" and forever 
  //  stay updated with the current year. If the value passed to this function 
  //  is '0' (zero), it will always return only the current year as for example 
  //  "1997" or "1998" etcetera.
  //
  var myCopyrightDateString = "";
  var todayDateObj = null;
  todayDateObj = new Date();    // Stores the current date and time from the
                                // client's system clock.
  var intYYYY = todayDateObj.getYear();
  // The JScript (JavaScript) method .getYear() returns a 
  // double-digit number (string) for years within the area of 
  // function and up to 1999. The method returns a four-digit 
  // number (string) for years within an area of function from 
  // 2000 and further on.
  if ( intYYYY < 2000 ) {
       // Year: Number of years since 1900.
       var strCurrentYear = "" + (intYYYY + 1900);  // Force number to a string.
  } else {
       var strCurrentYear = "" + (intYYYY);  // Force number to a string.
  }
  var strCopyYear = "" + copyYear;  // Force number to a string.
  // Make sure of the variable value if 'nothing' is the contents of the input.
  if( (strCopyYear == null) || (strCopyYear == "") || (strCopyYear == " ") || (strCopyYear == "  ") || (strCopyYear == "   ") || (strCopyYear == "    ") || (strCopyYear.length != 4) ){
    strCopyYear = "0";
  }
  // Test input for being a number.
  for (var i=0; i<strCopyYear.length; i++) {
    if ( ( strCopyYear.charAt(i) < "0" ) || ( strCopyYear.charAt(i) > "9" ) ) {
      strCopyYear = "0";
      break;  // One of the input characters is not a number, we have finished.
    }
  }
  // Test input integer-number of the start copy year for being in range - do not allow a value of zero (nothing).
  if ( (parseInt(strCopyYear, 10) <= 1899) || (parseInt(strCopyYear, 10) > parseInt(strCurrentYear, 10)) ) {
    strCopyYear = "0";
  }
  // Series of if else statements, sorts out which year part in a copyright notice to show.
  if (parseInt(strCopyYear, 10) == 0) {
    // ERROR in input: Current year is used.
    myCopyrightDateString = "" + strCurrentYear;  // Force number to a string.
  }else if (parseInt(strCopyYear, 10) == parseInt(strCurrentYear, 10)) {
    // 'copyYear' equals the current year.
    myCopyrightDateString = "" + strCopyYear;  // Force number to a string.
  }else if (parseInt(strCopyYear, 10) < parseInt(strCurrentYear, 10)) {
    // 'copyYear' is less than the current year.
    myCopyrightDateString = "" + strCopyYear + " - " + strCurrentYear;  // Force number to a string.
  }else {
    // ERROR.
    // Current year is used.
    myCopyrightDateString = "" + strCurrentYear;  // Force number to a string.
  }
  return (myCopyrightDateString);
}

// - End of JavaScript code and done hiding -->
</SCRIPT>

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

or... / eller...

1b Implementation: (How to use:) Distribute the code above to several documents by making a text file for example called "default.js" with the code above - but only the function's code, not the start and end script tag. Then insert the code below (make sure that the full path or the relative path to the text file is correct) in the <HEAD></HEAD> section of your HTML (HyperText Markup Language) documents. /
1b Implementering: (Sådan bruger du:) Distribuer ovenstående kode til flere dokumenter ved at lave en tekstfil for eksempel kaldet "default.js" med ovenstående kode - men kun funktionens kode, ikke start og slut script-tag'et. Indsæt derefter koden nedenfor (sørg for, at den fulde sti eller den relative sti til tekstfilen er korrekt) i <HEAD></HEAD> sektionen af dine HTML (HyperText Markup Language) dokumenter.



<SCRIPT SRC="./jscode/default.js" LANGUAGE="JavaScript" TYPE="text/javascript"></SCRIPT>

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

2 Implementation: (How to use:) Insert this code in the <BODY></BODY> section of your HTML (HyperText Markup Language) document, where you want the copyright notice to appear. /
2 Implementering: (Sådan bruger du:) Indsæt denne kode i <BODY></BODY> sektionen af dit HTML (HyperText Markup Language) dokument, hvor du vil, at meddelelsen om ophavsret skal vises.



<P ALIGN="left">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- Beginning of JavaScript Applet and hide from old browsers -----

var htmlCopyrightLine = "" + "&copy;" + copyrightDateString('1997') + " by Me, all rights reserved.";  // Force number to a string.

document.open();
document.write( htmlCopyrightLine );
document.close();

// - End of JavaScript code and done hiding -->
</SCRIPT>
</P>
<noscript>
<P ALIGN="left">
&copy;1997 - 2012 by Me, all rights reserved.
</P>
</noscript>

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

You can try the source code here: / Du kan afprøve kildekoden her:

 

Code extract: / Kode uddrag:
copyrightDateString(' ') Button
Result: / Resultat:

 

Purpose: / Formål:

The year in a copyright notice / Året i en meddelelse om ophavsret

Note: The year in a copyright notice does not really have much legal value, but is usually added to aid people who want to know whether the copyright still applies. As such it is supposed to be the year the work was published. Just using the current year really makes no sense whatsoever... However it has been seen done countless times. / Bemærk: Året i en meddelelse om ophavsret har ikke rigtig nogen juridisk værdi, men er normalt tilføjet for at hjælpe mennesker, der ønsker at vide, om ophavsretten stadig er gældende. Som sådan formodes det at være det år, hvor arbejdet blev offentliggjort. Blot at bruge det indeværende år giver virkelig overhovedet ingen mening... Men det har været set gjort utallige gange.

or... / eller...

See almost similar source code solution here: / Se næsten tilsvarende kildekode løsning her:

Overview - Function(s)... / Oversigt - Funktion(er)...

Developed and tested under browser(s): Microsoft Internet Explorer Version 8.x. / Udviklet og testet under browser(e): Microsoft Internet Explorer Version 8.x.

1 Implementation: (How to use:) Insert this code in the <BODY></BODY> section of your HTML (HyperText Markup Language) document, where you want the copyright notice to appear. /
1 Implementering: (Sådan bruger du:) Indsæt denne kode i <BODY></BODY> sektionen af dit HTML (HyperText Markup Language) dokument, hvor du vil, at meddelelsen om ophavsret skal vises.



<p align="left">
<script language="JavaScript" type="text/javascript">
<!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
var c_today = new Date();
var c_year = y2k(c_today.getYear());
document.write('&copy;1997 - '+c_year+' by Me, all rights reserved.');
//-->
</script>
</p>
<noscript>
<p align="left">
&copy;1997 - 2012 by Me, all rights reserved.
</p>
</noscript>

Conventions used for: Source code syntax highlighting. / Regler brugt til: Kildekode syntaks fremhævning.

You can see an example of the source code used here - at the bottom of the page (see the page mentioned below and see its JavaScript by using View Source): / Du kan se et eksempel på kildekoden brugt her - nederst på siden (se den side, der er nævnt nedenfor og se dens JavaScript ved at bruge Vis Kilde):

What's New? / Hvad nyt?Open this link in new window / Åben dette link i nyt vindue


(Geometric Shapes) Source code snippetsSource code snippets / Kildekode småstykker

- often included as functions for use in modules with program code, macros, and scripts etcetera. / - mange gange inkluderet som funktioner til brug i moduler med programkode, makroer og scripts og så videre.

The code might need some minor tweaks to run in your application. / Koden kan behøve nogle mindre ændringer for at kunne afvikles i dit anvendelsesområde.

Warning / Advarsel Licence: Free to use, but please share improvements. No warranty - use at own risk. /
Warning / Advarsel Licens: Fri brug, men del venligst forbedringer. Ingen garanti - brug på eget ansvar.

Warning: Don't run the script files without reading them first!
Total absence of any guarantee, warranty, or responsibility for script files, the script(s), the files they may produce, or the effects the script(s) or script-produced files may have. The script(s) is, after all, plain text. The burden is on the person using the script(s) to examine the script source code and determine whether or not a script is usable and safe. Operating systems and browsers are constantly changing. What works today may not work tomorrow!

Advarsel: Kør ikke script-filerne uden at læse dem først!
Totalt fravær af nogen form for garanti, garanti eller ansvar for script-filer, scriptet(scriptene), de filer, de kan producere eller de virkninger, scriptet(scriptene) eller scriptproducerede filer kan have. Scriptet(Scriptene) er, trods alt, almindelig tekst. Byrden er på brugeren af scriptet(scriptene) til at undersøge script kildekoden og afgøre, hvorvidt et script er brugbart og sikkert. Operativsystemer og browsere er under konstant forandring. Hvad fungerer i dag, fungerer muligvis ikke i morgen!


   Top of This Page
   Return
   Go to Home Page