From my main app page, Default.aspx I am popping up another page with window.open.
On that page I have a home link as a HyperLink that calls a Javascript function.
<asp:HyperLink id="lnkHome" runat="server" meta:resourcekey="lnkHome" NavigateUrl = " " onclick = "javascript:performRedirect()">
I am checking if the parent window is still running and if it is just closing this window, If not then redirecting back to the main window.
function performRedirect() {
if (parentExists()) {
$("a[id$= lnkHome]").attr('href', 'window.close();');
}
else {
$("a[id$= lnkHome]").attr('href', 'Default.aspx');
}
}
function parentExists() {
return (window.parent.location === window.location) ? false : true;
}
It works, but for some reason check fails and it always redirects me to Default.aspx even if calling page is still open. What do I need to change here? Unfortunately I have to use HyperLink control. I am using ASP.NET 4.0
I would check for
window.openerinstead ofwindow.parentsince you are opening the window usingwindow.openYour
parentExistisfunc become this:Or…