title: How to get the X & Y position of an iframe from within the Iframe?
body: <p>I have an iframe on a document. Using javascript, I can get the iframe's width and height and the document's width and height. I now need to get the x,y position of the iframe on the document from within the iframe.</p>
  
  <p>Code is something like:</p>
  
  <pre><code>&lt;html&gt;
  &lt;iframe&gt;
  var documentWidth = parent.window.innerWidth;
  var documentHeight = parent.window.innerHeight;
  var iframeWidth = window.innerWidth;
  var iframeHeight = window.innerHeight;
  var iframeX = ????
  &lt;/iframe&gt;
  &lt;html&gt;
  </code></pre>
  
  <p>I've tried window.offsetTop/Left, parent.window.offsetTop/Left, window.clientTop, etc and anything else I can find but keep getting 'undefined'.</p>
  
  <p>Both are on the same server so I don't think I have a cross domain issue.</p>
  
  <p>Any ideas?</p>
  
  <p>BTW I can't use JQuery for this. JS Only.</p>
  
  <p>Here is a bit more detail:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;div&gt;
  &lt;iframe name="iframe/123/Test"&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;script src="same domain"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;/iframe&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The script looks like this so far:</p>
  
  <pre><code>// JavaScript Document
  var documentWidth = parent.window.innerWidth;
  var documentHeight = parent.window.innerHeight;
  var iframeWidth = window.innerWidth;
  var iframeHeight = window.innerHeight;
  var iframeName = window.name;
  var iframeX = window.parent.document.getElementsByName(iframeName).offsetLeft;
  
  //Var Dumps
  document.write("Document Width: "+documentWidth+"&lt;br&gt;");
  document.write("Document Height: "+documentHeight+"&lt;br&gt;");
  document.write("Iframe Width: "+iframeWidth+"&lt;br&gt;");
  document.write("Iframe Height: "+iframeHeight+"&lt;br&gt;");
  document.write("Iframe X: "+iframeX+"&lt;br&gt;");
  </code></pre>
  
  <p>I get the following results on page in the iframe:</p>
  
  <pre><code>Document Width: 1566
  Document Height: 652
  Iframe Width: 300
  Iframe Height: 250
  Iframe X: undefined
  </code></pre>