Reputation: 1285
I am trying to refresh parent window from child window. Using following code in Child window this code reside in HTML widget.
parent.parent.window.opener.location.reload()
I am not adding any code in parent page since it is a moodle PHP page.
This code is working fine if both window reside in same origin.
I don't want to go with post-message()
. because I dont want to touch parent window code.
Can you help me with that? Just to refresh the page!!
Upvotes: 5
Views: 3237
Reputation: 1285
Finally, I found a solution to make this work.
1) You need to place on HTML file with below code on the domain where parent page resides.
pageReload.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.js"></script>
<script type="text/javascript">
function reload() {
parent.parent.window.opener.location.reload();
};
</script>
</head>
<body onload="reload()">
</body>
</html>
2) Load this HTML page in Child window of HTML Widget code. Add below line of code to load the above page.
window.location = "http://www.yourparentdomain.com/pageReload.html";
After this cross-domain page refresh will work.
Upvotes: 2
Reputation: 3761
You can't interact with a page from a different domain. See: https://en.wikipedia.org/wiki/Cross-site_scripting
Upvotes: 0