Welcome to WebmasterWorld Guest from 54.205.119.93

Forum Moderators: open

Message Too Old, No Replies

How to reload the parent frame

   
1:56 pm on Jan 1, 2014 (gmt 0)

5+ Year Member Top Contributors Of The Month



Sample parent code:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Parent</title>
</head>
<body>
<iframe src="https://dl.dropboxusercontent.com/u/4017788/Labs/child.html" width="200" height="100"></iframe>
</body>
</html>


See it in action:
[googledrive.com ]


Sample child code:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Child</title>
</head>
<body>
<button onclick="myFunction();">Try it!</button>
<script>
function myFunction() {
parent.location.reload();
}
</script>
</body>
</html>


I have tried many methods offered in similar questions to no avail, such as:

window.parent.location.reload();
top.location.reload();
etc.

What am I missing and what's the right approach?
5:54 am on Jan 4, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I think security is stopping you (same domain policy) try with both on googledrive or dropboxusercontent.
8:26 am on Jan 4, 2014 (gmt 0)

5+ Year Member Top Contributors Of The Month



I cannot put both frames on the same server.
For now I have found a workaround: document.referrer

Child:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Child</title>
</head>
<body>
<button onclick="myFunction();">Try it!</button>
<script>
function myFunction() {
window.parent.location = document.referrer;
}
</script>
</body>
</html>
2:11 am on Jan 31, 2014 (gmt 0)



FWIW, I think that Dave is right on this being a security issue. You're trying to get one website to refresh another, which usually isn't going to work.

If your workaround is working now, I wouldn't be surprised if it's not working on all browsers, or if it stops working in the next couple of browser updates. So don't rely on that too much.