brandnewbox.co.uk

Interstitial pages with javascript - Part 1

When you click on a link an interstitial page (usually an advert) appears before you are shown the new page that you clicked to view.

doInterstitial() is a simple javascript function that rewrites all links on a page:

function doInterstitial(newURL, time) {
      var links = document.getElementsByTagName('a');
      for( var i=0; i<links.length; i++) {
          var oldURL = links[i].href;
          links[i].href = newURL + '?oldURL=' + oldURL + '&timer=' + time;
      }
}

and can be called on page load (passing the advert url and a time duration for the advert):

<body onload="doInterstitial('ad.html', 2000);">

The advert needs to wait the required duration and then forward the user onto the page they required.

» Part 2