Solved

Get The Full Position Of An IFrame

Posted on 2001-08-10
3
1,305 Views
Last Modified: 2012-06-21
I need to figure out the exact position of an IFrame without setting any stylesheets for it (no id, no position). Normaly this works fine with offsetLeft, but not if the IFrame is created in an table. Here ist the code on which I am working.




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Untitled</title>
     <SCRIPT language=JavaScript>
     <!--
     function test() {
          document.write('<iframe s'+'rc="http://www.yahoo.com" width=400 height=300 marginwidth=0 ');
          document.write('marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no>');
          document.write('</iframe>');
     }
     // -->
     </SCRIPT>
</head>
<body>
<table border=0>
<tr>
     <td>Tested</td>
     <td>
     <script language=javascript>
     <!-- //
     test();
     // -->
     </script>
     </td>
</tr>
</table>
     <script language=javascript>
     for(i = 0; i < top.document.all.length; i++){
          if (top.document.all(i).tagName == "IFRAME") {
          var oElement = top.document.all(i);
              alert(i + ": Left: " + oElement.offsetLeft + ", Top: " + oElement.offsetTop);
          }
     }
     </script>
</body>
</html>




0
Comment
Question by:Maniac7791
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
MCM earned 200 total points
ID: 6372588
How are these:

function getTop(obj)
     {
     var height=0;
     while ((obj.offsetParent))
          {
               height+=obj.offsetTop;
               obj=obj.offsetParent;
          };
     return height;
     }

function getLeft(obj)
     {
     var left=0;
     while ((obj.offsetParent))
          {
               left+=obj.offsetLeft;
               obj=obj.offsetParent;
          };
     return left;
     }

But for IE 5+ only...i'm pretty sure older IE & NS &c. won't tell you anything about positioning, so you might figure out a way you don't need the info.
0
 

Author Comment

by:Maniac7791
ID: 6375373
Thanks, this sounds good, and i will check if it works for me.
0
 

Author Comment

by:Maniac7791
ID: 6383190
Working with IE4+ and that was what I wanted. Many Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now