Bottom of This Page |
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.
<HEAD></HEAD>
section
of your HTML (HyperText Markup Language) document. /
<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 = "" + "©" + 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"[>]
// ©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.
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. /
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.
<BODY></BODY>
section
of your HTML (HyperText Markup Language) document, where you want
the copyright notice to appear. /
<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 = "" + "©" + 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">
©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:
Purpose: / Formål:
It's simple to display a dynamic date so you never need to change your copyright notice on your internet homepage documents when the year changes and you can forget about making sure you don't look stupid, or give the impression your site is out of date and unused, at the beginning of every year. / Det er nemt at vise en dynamisk dato, så du aldrig behøver at ændre din meddelelse om ophavsret på dine internet hjemmeside dokumenter, når året skifter, og du kan glemme alt om at sikre, at du ikke ser dum ud, eller give indtryk af at dit websted er forældet og ubrugt ved begyndelsen af hvert år.
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
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.
<BODY></BODY>
section
of your HTML (HyperText Markup Language) document, where you want
the copyright notice to appear. /
<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('©1997 - '+c_year+' by Me, all rights reserved.');
//-->
</script>
</p>
<noscript>
<p align="left">
©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
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.
Licence: Free to use, but please
share improvements.
No warranty - use at own risk. /
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!
|