I have already seen many questions on stackoverflow about this theme, but nothing helps.
I have a simple situation:
A parent page:
<!DOCTYPE html>
<html>
<head>
<title>title</title>
</head>
<body>
<script type="text/javascript">
var global = 'I am global variable';
</script>
<iframe name="main" src="main.php"></iframe>
</body>
</html>
So... the child iframe page
<!DOCTYPE html>
<html>
<head>
<title>iframe window</title>
</head>
<body>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<script type="text/javascript">
var local = 'i am local variable';
</script>
</body>
</html>
You see, nothing difficult.
If I find child iframe in index.php (parent) - it returns window object of child(in console), and all is great.
But if I want find the parent with any of next commands:
window.frames.parent
window.frames.top
or finding variable
window.frames.parent.global
It returns the object window of the same page, but not the parent.
It's working in WAMP and have a simple structure with index.php and main.php. Any ideas?
尝试这个:
alert(parent.global); // inside main.php(child) file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.