I know the subject might be a bit confusing, but in my searching i found LOTS of questions about getting value from parent page when inside iframe. This is not what i want to achive.
I have 2 html pages and a js file. This is how they look:
outer.html:
...
<body>
<iframe src="./inner.html"></iframe>
</body>
....
inner.html
<head>
<script type="text/javascript">
var somevar = { id:302 };
(function() {
var ml = document.createElement('script');
ml.type = 'text/javascript';
ml.async = true;
ml.src = './some.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ml, s);
}) ();
</script>
</head>
some.js:
console.log(parent.somevar);
What im expecting is that code in some.js would output the “somevar” object, but it outputs ‘undefined’. If i run the inner.html directly (not through iframe element) then it outputs the object fine.
If i do
console.log(parent);
I get the DOM of the parent window (outer.html).
So my question is – how do i get the DOM of inner.html from the some.js file (or other script tags in the inner.html)
BR/Sune
console.log(somevar)?