≡ Menu

Table of contents problem (iframe linking) fixed

Yesterday I was able to fix the Javascript code that prevented the left-side table of contents from working properly in the Safari and Google Chrome browsers. I tweaked a solution suggested in an online comment (#7) by “inimino” at Targeting an anchor within iFrame; his(?) original code is in the source of this page.

function scrollToFrag(frag){
// Called by clicking on a link in the left-side table of contents in the main page.
// The argument ‘frag’ is the element identifier of a paragraph in the agreement draft,
// which is located is is in an iframe (‘ContentFrame’) on the right of the main page.

  objTemp=top.frames[“ContentFrame”].document.getElementById(frag);
  objTemp.style.display=’block’;
  tmp = getPos(objTemp);
    // getPos is a routine that determines where in the document
    // the ‘frag’ paragraph is located
  top.frames[“ContentFrame”].scrollTo(0,tmp);
    // I had to prepend the ‘top.frames[“ContentFrame”].’ part
    // to make it work in Safari and Google Chrome.
    // The original code is more succinct; I expanded it
    // for debugging purposes.
}

function getPos(e) {
  var y=0;
  do{
    var yd = e[‘offsetTop’];
    y += isNaN(yd)?0:yd;
    e = e.offsetParent;
    } while (e && e!=document.body);
  return y;
  }