topical media & game development

talk show tell print

#javascript-code-09-iframe.js / js



  // Let’s assume that we already have an IFrame in the page
  // with an ID of ‘iframe’
  var iframe = document.getElementById(“iframe”);
  
  // Locate all <a> elements on the page
  var a = document.getElementsByTagName(“a”);
  for ( var i = 0; i < a.length; i++ ) {
  
      // Bind a click handler to the <a>
      a[i].onclick = function(e) {
          // Set the IFrame’s location
          iframe.src = this.href;
  
          // Prevent the browser from ever visiting the web site pointed to from
          // the <a> (which is the default action)
          return stopDefault( e );
      };
  
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.