4

I've got a simple html code with an iframe on it and I want to access a global variable outside the iframe on the parent.

Anyone knows why chrome doesn't want to make me happy? :)

The code of the iframe works fine in ff,ie,... but not chrome.

Html Code :

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script> var one = "two"; </script>
.....
<body>    
<iframe name="process" id="process" src="" frameborder=1></iframe>    
</body> 
</html>

Iframe Code :

<html>
<head>
<script> alert("Inside step 1 : "+parent.one);  </script>
</head>
<body>
  STEP 1
</body> 
</html>
Tony
  • 3,425
  • 10
  • 30
  • 46
  • Possible duplicate: http://stackoverflow.com/questions/5777289/cant-access-content-of-another-frame-in-chrome – ean5533 Dec 28 '11 at 16:14
  • @ean5533 is not the same thing, as i'm accesing a global scope variable, not a content from different frame with their id's. Also this is an iframe – Tony Dec 28 '11 at 16:29

1 Answers1

1

Unfortunately, you can't do that in JavaScript. Each iframe is contained in its own document. This document object contains the global scope of that iframe. You can't access anything outside of the global scope, so the iframe can only use variables created inside the iframe.

Matt Bradley
  • 4,395
  • 1
  • 20
  • 13
  • Well, if I put the provided HTML into a test page, I can call `alert(parent.one)` on the iframe correctly... – josh.trow Dec 28 '11 at 16:16
  • @Matt Bradley Nope, as i said in ff and ie i can access variables in the global scope inside the iframe. You can access variables outside the iframe if the principal and the iframe are in the same host.... no window.message needed as they're in the same domain – Tony Dec 28 '11 at 16:17