i know this question was asked before but i, can't get this to work.
I have a .aspx which contains a function on the onunload body tag. This will refresh the parent page.
At this point, i need to know if the page was refreshed/reloaded, because this logic will trigger the func call everytime and close my "child" page.
This is my code
<script type="text/javascript">
function refreshparent(){
window.opener.location.reload(true);
window.close();
}
</script>
This is whay i want to do
<script type="text/javascript">
function refreshparent(){
if(page.wasclosed){
window.opener.location.reload(true);
window.close();
}else{
//do nothing
}
}
</script>
You can try something like this
window.onload = function () {
if (!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload();
}
}
once the page refreshed the #loaded is added to the url and once #loaded us detected it stops refreshing meaning "true". then you can use search params anywhere to see if the page was reloaded. You can add this in a setTimeout function or something else.