Solved

Get The Full Position Of An IFrame

Posted on 2001-08-10
3
1,308 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

792 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