Solved

Get The Full Position Of An IFrame

Posted on 2001-08-10
3
1,310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

751 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