≡ 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.

  tmp = getPos(objTemp);
    // getPos is a routine that determines where in the document
    // the ‘frag’ paragraph is located
    // 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;
    var yd = e[‘offsetTop’];
    y += isNaN(yd)?0:yd;
    e = e.offsetParent;
    } while (e && e!=document.body);
  return y;

{ 0 comments… add one }

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.