Accessing a global variable using Chrome

I have a simple html code with an iframe on it and I want to get a global variable outside the iframe on the parent.

Does anyone know why chrome doesn't want me to be happy? :)

Iframe code works fine in ff, i.e. .... 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> 
+4
source share
1 answer

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

+1
source

Source: https://habr.com/ru/post/1388328/


All Articles