There are many exactly similar questions here on SO, but none give the correct answer, hence forcing me to ask this as a new question. Please consider this before marking my question as a duplicate.
I tried the answers posted in the other questions and none of them work correctly for me. Here is the code I have:
In the parent window:
<a href="createfolder.htm" onClick="return popup(this, 'createfolder', 600, 200);">Create new folder</a>
In the Javascript file:
function popupClosed() {
//alert('About to refresh');
window.location.href = window.location.href;
//window.opener.location.reload();
}
function popup(mylink, windowname, w, h)
{
//if (! window.focus) return true;
var href;
if (typeof(mylink) == 'string')
href = mylink;
else
href = mylink.href;
var left = (window.innerWidth/2)-(w/2);
var top = (window.innerHeight/2)-(h/2);
var win = window.open(href, windowname, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
win.onunload = function() {
popupClosed();
}
return false;
}
The problem I am having is that it is refreshing the parent window as soon as the link is clicked - which is not desired. It does also refresh the parent window after the popup is closed. However I want to avoid the refresh that occurs when the link is clicked.