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

Redirect / Omdiriger

Description: Split a HTML (HyperText Markup Language) document's URL (Uniform Resource Locator) up in parts - but only URLs from a Hard Disk Drive. Used here to let the user redirect a page to a similar page placed on another drive letter - for example, change from a computer drive to a network drive. / Beskrivelse: Split et HTML (HyperText Markup Language) dokuments URL (Uniform Resource Locator) op i dele - men kun URL'er fra et harddisk drev. Bruges her til at lade brugeren omdirigere en side til en tilsvarende side placeret på et andet drev bogstav - for eksempel skift fra et computer drev til et netværksdrev.

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 <HEAD></HEAD> section of your HTML (HyperText Markup Language) document. /
1 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 -----

// Initialize variables for global use.
var loc = location.href;  // href location of document.
loc = loc.toString();
loc = loc.toLowerCase();
var lenptype = loc.indexOf(":");  // Length of the protocol type (such as http:, ftp:, gopher:, and so on).
var ptype = loc.substring(0,(lenptype + 1));  // Extract the protocol type characters from pos 0 up to but not including pos ('lenptype' + 1).
if ( ptype == "file:" ) {
     var docLocal = true;     // Document Local.
} else {
     var docLocal = false;    // Document not Local.
}

var loc_href = self.location.href;       // href location of document.
loc_href = loc_href.toString();
//loc_href = loc_href.toLowerCase();

var loc_path = self.location.pathname;   // Pathname location of document.
loc_path = loc_path.toString();
//loc_path = loc_path.toLowerCase();

var loc_search = self.location.search;   // Search location of document.
loc_search = loc_search.toString();
//loc_search = loc_search.toLowerCase();

var questionMarkConstant = "?";  // Question mark constant.
var equalSignConstant = "=";  // Equal-sign constant.
var ampersandConstant = "&";  // Ampersand constant.
var TypedURL;  // Typed URL.
var goLocation;  // Go to location (URL).
var openLocation;  // Open location (URL).
var urlPart1Str;  // Stores URL (Uniform Resource Locator) Part 1 of URL (Uniform Resource Locator).
var urlPart2Str;  // Stores URL (Uniform Resource Locator) Part 2 of URL (Uniform Resource Locator). [ This document's drive letter. ]
var urlPart3Str;  // Stores URL (Uniform Resource Locator) Part 3 of URL (Uniform Resource Locator).
var urlPart4Str;  // Stores URL (Uniform Resource Locator) Part 4 of URL (Uniform Resource Locator). [ This document's file name. ]
var urlPart5Str;  // Stores URL (Uniform Resource Locator) Part 5 of URL (Uniform Resource Locator).
TypedURL = "";
goLocation = "";
openLocation = "";
urlPart1Str = "";
urlPart2Str = "";
urlPart3Str = "";
urlPart4Str = "";
urlPart5Str = "";

// Split this document's URL (Uniform Resource Locator) up in parts - but only URLs from a Hard Disk Drive.

//   The method charAt is used to extract a single character from a 
//     string at start position.
//   The method substring is used to extract a range of characters 
//     from a string from start position up to but not including end 
//     position.
//   The method indexOf is used to search for character with a string - 
//     searches from the beginning (left side) of the string. Optional 
//     second argument that specifies an initial index at which to start 
//     the search.
//   The method lastIndexOf is used to search for character with a 
//     string - searches from the end (right side) of the string. 
//     Optional second argument that specifies an initial index at 
//     which to start the search.
//   Character positions are zero based, so that all indices must fall 
//     between 0 and one less than the length.
//   In JavaScript, the backslash (\) is an escape character.
//     An escape character enables you to output characters you wouldn't 
//     normally be able to, usually because the browser will interpret it 
//     differently to what you intended. 

if ( docLocal ) {
  // Document Local.
  if ( loc_href.indexOf("/",0) != -1 ) {
    // The slash (/) is used as separator in the string.
    urlPart1Str = "" + loc_href.substring(0,(loc_href.indexOf(loc_path,0)+1));  // Force number to a string.
    urlPart2Str = "" + loc_path.charAt(1);  // Force number to a string.
    urlPart3Str = "" + loc_href.substring((loc_href.indexOf(loc_path,0)+2),((urlPart1Str.length-1)+loc_path.length));  // Force number to a string.
    urlPart4Str = "" + urlPart3Str.substring((urlPart3Str.lastIndexOf("/")+1),urlPart3Str.length);  // Force number to a string.
    urlPart3Str = "" + urlPart3Str.substring(0,(urlPart3Str.length-urlPart4Str.length));  // Force number to a string.
    urlPart5Str = "" + loc_href.substring((urlPart1Str.length+urlPart2Str.length+urlPart3Str.length+urlPart4Str.length),loc_href.length);  // Force number to a string.
  } else if ( loc_href.indexOf("\\",0) != -1 ) {
    // The backslash (\) is used as separator in the string.
    urlPart1Str = "" + loc_href.substring(0,(loc_href.indexOf(loc_path,0)+1));  // Force number to a string.
    urlPart2Str = "" + loc_path.charAt(1);  // Force number to a string.
    urlPart3Str = "" + loc_href.substring((loc_href.indexOf(loc_path,0)+2),((urlPart1Str.length-1)+loc_path.length));  // Force number to a string.
    urlPart4Str = "" + urlPart3Str.substring((urlPart3Str.lastIndexOf("\\")+1),urlPart3Str.length);  // Force number to a string.
    urlPart3Str = "" + urlPart3Str.substring(0,(urlPart3Str.length-urlPart4Str.length));  // Force number to a string.
    urlPart5Str = "" + loc_href.substring((urlPart1Str.length+urlPart2Str.length+urlPart3Str.length+urlPart4Str.length),loc_href.length);  // Force number to a string.
  }
} else {
  // Document not Local.
  // Do nothing.
  //;
}
//alert("URL - Part 1: \"" + urlPart1Str + "\", Part 2 (drive letter): \"" + urlPart2Str + "\", Part 3: \"" + urlPart3Str + "\", Part 4 (file name): \"" + urlPart4Str + "\", and Part 5: \"" + urlPart5Str + "\".");  // Only for the purpose of debugging.

function jump_menu() {
  // This function supports the UNIT jump menu 
  // and jumps directly to the page in 
  // the variable 'goLocation'.
     // Find out what is currently selected.
     var loc = document.info.jumpMenu.options[document.info.jumpMenu.selectedIndex].value;
     var goLocation = "-";  // Go to location (URL).
     // Give the person the page they selected.
     if (loc == " "){
          goLocation = "-";
     }else{
          goLocation = "" + urlPart1Str + loc + urlPart3Str + urlPart4Str + urlPart5Str;  // Force number to a string.
     }
     if (goLocation != "-"){
          top.location = goLocation;
     }else{
          alert("Select something.");
     }
  return;
}

function openPopUpURLjm() {
  // This function supports the UNIT jump menu 
  // and jumps directly to the page in 
  // the variable 'goLocation' (Opens in a new Pop Up window).
     // Find out what is currently selected.
     var loc = document.info.jumpMenu.options[document.info.jumpMenu.selectedIndex].value;
     var goLocation = "-";  // Go to location (URL).
     // Give the person the page they selected.
     if (loc == " "){
          goLocation = "-";
     }else{
          goLocation = "" + urlPart1Str + loc + urlPart3Str + urlPart4Str + urlPart5Str;  // Force number to a string.
     }
     if (goLocation != "-"){
          // alert("URL GO to: \"" + goLocation + "\".");
          openLocation = goLocation;
          //alert("Sorry, the page '" + openLocation + "' you requested was not found.");
          var aPopUp = window.open(openLocation,"PopUpURLjm","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=450,height=500");
     }else{
          alert("Select something.");
     }
  return;
}

function doOnLoad() 
{
  // Dynamically change the selections made.
  document.info.jumpMenu.options[0].selected=1;
  document.info.output.value = "" + urlPart1Str;  // Output. // Force number to a string.
  document.info.output2.value = "" + urlPart3Str + urlPart4Str + urlPart5Str;  // Output. // Force number to a string.
  return;
}

// - End of JavaScript code and done hiding -->
</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> tag of your HTML (HyperText Markup Language) document. /
2 Implementering: (Sådan bruger du:) Indsæt denne kode i <BODY> tag'get af dit HTML (HyperText Markup Language) dokument.



<BODY onLoad="window.setTimeout('doOnLoad();',1000)">

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

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



<p>&nbsp;</p>

<CENTER>
<DIV ALIGN="CENTER">
  <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
    <TR>
      <TD ALIGN="LEFT" VALIGN="MIDDLE">
<FORM NAME="info">
        <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
          <TR>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" bgcolor="#FFFFFF" NOWRAP>&nbsp;</TD>
            <TD ALIGN="RIGHT" VALIGN="MIDDLE" bgcolor="#FFFFFF" NOWRAP>
                &nbsp;
                <INPUT TYPE="text" NAME="output" SIZE="20"
                   onFocus="this.blur()"
                   onSubmit="return false" ><!--
                   &nbsp;
                &nbsp;
            --></TD>
            <TD ALIGN="RIGHT" VALIGN="MIDDLE" bgcolor="#FFFFFF" NOWRAP>
              <select NAME="jumpMenu">
              <OPTION VALUE=" " SELECTED> </OPTION>
              <OPTION VALUE="A"> A</OPTION>
              <OPTION VALUE="B"> B</OPTION>
              <OPTION VALUE="C"> C</OPTION>
              <OPTION VALUE="D"> D</OPTION>
              <OPTION VALUE="E"> E</OPTION>
              <OPTION VALUE="F"> F</OPTION>
              <OPTION VALUE="G"> G</OPTION>
              <OPTION VALUE="H"> H</OPTION>
              <OPTION VALUE="I"> I</OPTION>
              <OPTION VALUE="J"> J</OPTION>
              <OPTION VALUE="K"> K</OPTION>
              <OPTION VALUE="L"> L</OPTION>
              <OPTION VALUE="M"> M</OPTION>
              <OPTION VALUE="N"> N</OPTION>
              <OPTION VALUE="O"> O</OPTION>
              <OPTION VALUE="P"> P</OPTION>
              <OPTION VALUE="Q"> Q</OPTION>
              <OPTION VALUE="R"> R</OPTION>
              <OPTION VALUE="S"> S</OPTION>
              <OPTION VALUE="T"> T</OPTION>
              <OPTION VALUE="U"> U</OPTION>
              <OPTION VALUE="V"> V</OPTION>
              <OPTION VALUE="W"> W</OPTION>
              <OPTION VALUE="X"> X</OPTION>
              <OPTION VALUE="Y"> Y</OPTION>
              <OPTION VALUE="Z"> Z</OPTION>
              </select>
            </TD>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" bgcolor="#FFFFFF" NOWRAP><!--
                &nbsp;
                --><INPUT TYPE="text" NAME="output2" SIZE="60"
                   onFocus="this.blur()"
                   onSubmit="return false" ><!--
                   &nbsp;-->
                &nbsp;
            </TD>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" bgcolor="#FFFFFF" NOWRAP>&nbsp;</TD>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" NOWRAP>&nbsp;</TD>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" NOWRAP><INPUT TYPE="button" NAME="GoUrlBtn1jm" VALUE="GO!" onClick="jump_menu()"></TD>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" NOWRAP>&nbsp;</TD>
            <TD ALIGN="LEFT" VALIGN="MIDDLE" NOWRAP><INPUT TYPE="button" NAME="GoUrlBtn2jm" VALUE="GO (new window)!" onClick="openPopUpURLjm()"></TD>
          </TR>
        </TABLE>
</FORM>
      </TD>
    </TR>
  </TABLE>
</DIV>
</CENTER>

<p>&nbsp;</p>

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

or... / eller...

Warning / AdvarselThe next 2 pages linked to in the next 2 links below will only work when the pages are downloaded**) and saved on your computer. / De næste 2 sider linket til i de næste 2 links nedenfor vil kun virke, når siderne er download'et**) og gemt på din computer.

Purpose: / Formål:

You can download**) a version of the source code here: / Du kan downloade**) en version af kildekoden her:

[JavaScript (JScript)] Download Redirect: redirask.htm / [JavaScript (JScript)] Download Omdiriger: redirask.htmOpen this link in new window / Åben dette link i nyt vindue*)

*) Automatically redirect page. / Automatisk omdiriger side.
**) How to download a file to your computer: Simply click the RIGHT mouse button over the graphic "Link" Image. From the popup menu, Netscape users will select "Save link as" and Internet Explorer users will select "Save destination as". / Sådan downloades en fil til din computer: Klik simpelt hen på den HØJRE museknap over grafik "Link" billedet. Fra pop-up menuen skal Netscape brugere vælge "Gem link som" og Internet Explorer brugere vælge "Gem destination som".


See (and download**)) similar source code for JavaScript here: / Se (og download**)) tilsvarende kildekode for JavaScript her:

Purpose: / Formål:

[JavaScript (JScript)] Download ! Go Index: go_index.htm / [JavaScript (JScript)] Download ! Go Index: go_index.htmOpen this link in new window / Åben dette link i nyt vindue*)

*) Automatically redirect page. / Automatisk omdiriger side.
**) How to download a file to your computer: Simply click the RIGHT mouse button over the graphic "Link" Image. From the popup menu, Netscape users will select "Save link as" and Internet Explorer users will select "Save destination as". / Sådan downloades en fil til din computer: Klik simpelt hen på den HØJRE museknap over grafik "Link" billedet. Fra pop-up menuen skal Netscape brugere vælge "Gem link som" og Internet Explorer brugere vælge "Gem destination som".


(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