faqts : Computers : Programming : Languages : JavaScript : Frames

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

147 of 168 people (88%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

Can I position an IFRAME?
How can I move an IFRAME?

Mar 28th, 2000 11:36
Martin Honnen,


Using CSS you can position an IFRAME like every other HTML element e.g.
  <IFRAME ID="anIframe" NAME="anIframe"
          SRC="http://javascript.faqts.com"
          STYLE="position: absolute; left: 100px; top: 100px;" 
  ></IFRAME>
Moving then works as with other positioned elements by changing 
style.left/style.top:
  var ifr = 
    document.all ? document.all['anIframe'] : 
      document.getElementById('anIframe');
  ifr.style.left = '200px';
  ifr.style.top  = '300px';

Here is a complete example:

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>
function moveRight () {
  var ifr = 
    document.all ? document.all['anIframe'] : 
      document.getElementById('anIframe');
  ifr.style.left = (parseInt(ifr.style.left) + 10) + 'px';
}
</SCRIPT>
</HEAD>
<BODY>
<A HREF="javascript: moveRight(); void 0">
move iframe right
</A>
<IFRAME ID="anIframe" NAME="anIframe"
        SRC="http://javascript.faqts.com"
        STYLE="position: absolute; top: 100px; left: 100px;"
>
</IFRAME>
</BODY>
</HTML>