Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get The Full Position Of An IFrame

Posted on 2001-08-10
3
Medium Priority
?
1,313 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 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

722 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