Solved

Get The Full Position Of An IFrame

Posted on 2001-08-10
3
1,309 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

685 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