Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Odds and Sods

You are here: irt.org | Articles | JavaScript | Miscellaneous | Odds and Sods

Published on: Wednesday 5th March 1997 By: Martin Webb

Frames

To remove frames:

<a href="http://www.yahoo.com" target="_top">Remove Frames</a>

To check if the current document is loaded in a frame:

<body onLoad="if (parent.location.href != self.location.href)
    {... do something ...}; return true;">

To change the contents of two or more frames:

<a href="JavaScript:jump()">Change Frames</a>

<script language="JavaScript"><!--
function jump() {
  parent.frame1.location.href =
    'http://www.yahoo.com';
  parent.frame2.location.href =
    'http://www.altavista.digital.com/';
}
//--></script>

Mailto

The following mailto attributes do not currently work with Internet Explorer:

Dates

To reformat the last modified date:

<script language="JavaScript"><!--
function makeArray0() {
  for (i = 0; i<makeArray0.arguments.length; i++)
     this[i] = makeArray0.arguments[i];
}

var days = new makeArray0(
  'Sunday', 'Monday', 'Tuesday', 'Wednesday',
  'Thursday', 'Friday', 'Saturday'
);

var months = new makeArray0(
  'January', 'February', 'March',
  'April', 'May', 'June',
   'July', 'August', 'September',
  'October', 'November', 'December'
);

function nths(day) { 
  if (day == 1 || day == 21 || day == 31)
    return 'st';
  else
   if (day == 2 || day == 22)
     return 'nd';
   if (day == 3 || day == 23)
     return 'rd';
   else return 'th';
}

function y2k(number) {
  return (number < 1000) ? number + 1900 : number;
}

var last = document.lastModified;
var date = new Date(last);
document.write(
  'Last updated on ' + days[date.getDay()] + ' ' +
  date.getDate() + nths(date.getDate()) + ' ' +
  months[date.getMonth()] + ', ' +
  (y2k(date.getYear())) + '.'
);
//--></script>

Which produces:

Refresh

To refresh the current page 10 seconds after it has loaded:

<body onLoad="window.setTimeout('RefreshScreen()',10000)">

<script language="JavaScript"><!--
function RefreshScreen()
{
     location.href = self.location.href;
}
//--></script>

Or:

<body onLoad="window.setTimeout('RefreshScreen()',10000)">

<script language="JavaScript"><!--
function RefreshScreen()
{
     history.go(0);
}
//--></script>

Alternatively use the following in the HEAD section:

<META HTTP-EQUIV="Refresh" CONTENT="10">

View the profile on Martin Webb and the list of other Articles by Martin Webb.


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 21st December 2007. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.