window.opener.closed return an permission denied error when opener window is closed.

There are two aspx pages, page1.aspx and page2.aspx.  There is an 'Open' button on page1, click this button, I open an separate browser window from which I open an separate browser window with url being page2.aspx.  Both pages are in same domain.

On page2.aspx, every 5 seconds, it calls a javascript function that will check the "Closed" property of opener window. If the opener window is not closed, it return me false, which is correct. BUT if the opener window is closed, I am getting a permission denied Javascript runtime error.

I am running the application on IE6.

Here is the code:

For page1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<script language="javascript">

function func1()

{

window.open('Page2.aspx', 'name');

}

</script>

<body>

<form id="form1" runat="server">

<asp:Button ID="OpenBtn" runat="server" OnClientClick="func1()" Text="Open" /><br />

<br />

</form>

</body>

</html>

//For Page2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Page2.aspx.cs" Inherits="Page2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="PAGE2"></asp:Label></div>

</form>

</body>

</html>

<script language="javascript">

window.setTimeout(abc, 5000)

function abc()

{

debugger

if (window.opener.closed)

{

//do something

}

}

 

</script>

 

 

 

0
Yuhua
8/30/2006 5:33:44 PM
asp.net.client-side 24353 articles. 2 followers. Follow

6 Replies
2841 Views

Similar Articles

[PageSpeed] 30
Get it on Google Play
Get it on Apple App Store

I ran into the same problem but got around it by putting the check for window.opener.closed in a try - catch block so when it errors it's most likely because it's been closed.

try
{
  if(window.opener.closed)
  {
     //do something
  }
}
catch(err)
{
  //something else
}
 
0
alcsharp
9/1/2006 5:13:51 AM

I've tested on IE6 and FX1.0.7.

On IE, it just seems to be ok, even if the opener has been closed...

In FX instead the opener reference is null when the opener has closed.

In any case, the code might just look like:

   if(window.opener == null || window.opener.closed) ...

That is, check for the opener reference not to be null. Handling exceptions in javascript is not yet widly supported i'm afraid.

-LV


Julio P. Di Egidio
Software Analyst Programmer
=BUSINESS AND SCIENTIFIC=
=SOFTWARE DEVELOPMENT=
http://julio.diegidio.name

(Peace X Love] = [++1)
0
LudovicoVan
9/1/2006 6:29:14 AM

I'm working in IE6 as well but had the same results as the original post. 

When the opener is closed, I get the same Permission Denied error.  I also tried the check for
if(window.opener == null) ...   but it never seems to pass this condition, even if the opener window is closed. 

That's why the only way I was able to get around it was to catch the permission denied error....tho i'm open to another way as well.  In my case it's an internal web app which will run only on IE so I'm allrite, but it's good to be aware of the differences with other browsers especially with exception handling so I can prepare if we ever allow external access.

0
alcsharp
9/1/2006 2:26:30 PM

Ok, i don't question your results, as there might be differences with operating system setup in general.

Anyway, would you mind trying the following on your system? This might give a hint:

   alert(window.opener);

Let me know, this is interesting...

-LV


Julio P. Di Egidio
Software Analyst Programmer
=BUSINESS AND SCIENTIFIC=
=SOFTWARE DEVELOPMENT=
http://julio.diegidio.name

(Peace X Love] = [++1)
0
LudovicoVan
9/1/2006 2:35:42 PM

Ok, I tried the alert(window.opener) when the parent window was still open and when it was closed and I recevied the following text in the alert window both times: "[object]"

I also tried alert(window.opener.document.title) with the parent window open (no problems) and again with it closed (again got the "permission denied error")

This is interesting.. the window.opener always has a reference to an object, even when closed; however, I can't access the object at all.

0
alcsharp
9/1/2006 6:55:03 PM
It is so interesting that it behaves differently even all in IE6. I am thinking if it has to do with the windows update. I have all the latest updates installed and my operation system is XP+sp2.  I am using "alcsharp"s  work around solution temporarily. But unfortunately, for me, I am developing a real application.  So, if anyone know other solution, let me know.
0
Yuhua
9/5/2006 11:41:03 PM
Reply:

Similar Artilces:

Open Popup Window and Close the window that Opened it
I'm using some code that I found on this site to open a Popup window with a Button Click for a Crystal Report: Dim PopUpScript As String = "<script language='javascript'>" + "window.open(" & Chr(39) & strExportFile & Chr(39) & ");</script>" Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopUpWindow", PopUpScript, False) After the Popup Window shows the Report I would like to close the window that opened this popup window.  Thanks, Mark just add window.close(); in Dim PopUpScript As String ...

superreview cancelled: [Bug 241972] new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins : [Attachment 225294] close blank window
Marria Nazif <marria@gmail.com> has cancelled Marria Nazif <marria@gmail.com>'s request for superreview: Bug 241972: new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins https://bugzilla.mozilla.org/show_bug.cgi?id=241972 Attachment 225294: close blank window https://bugzilla.mozilla.org/attachment.cgi?id=225294&action=edit ...

superreview requested: [Bug 241972] new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins : [Attachment 225294] close blank window
Marria Nazif <marria@gmail.com> has asked Darin Fisher (Google) <darin@meer.net> for superreview: Bug 241972: new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins https://bugzilla.mozilla.org/show_bug.cgi?id=241972 Attachment 225294: close blank window https://bugzilla.mozilla.org/attachment.cgi?id=225294&action=edit ------- Additional Comments from Marria Nazif <marria@gmail.com> This is a first try at closing the window after the external app handler has done its work. This se...

New 3.5.2 version does not have a X to close the last or sole open window, when all older versions had it, I want (need) this X back to close the last window opened.
Name: J.Elderberry Product: Firefox Summary: New 3.5.2 version does not have a X to close the last or sole open window, when all older versions had it, I want (need) this X back to close the last window opened. Comments: When one wants to remove all open web page(s) and keep a empty open Firefox, with nothing open in case one needs it, we now can't do it, we have to keep the last window opened. This is very annoyind to me because in my work, I have the good habit to close every web sites when my consultation of those sites are finished. It's like closing a dictionaty w...

window.close() casuing popup window to hang when closing/opening again and again..
I have a parent window which opens a child window. the child window has a close button which I placed javascript code "window.close()" to close it. so i close the child window and re-open it again from the parent window ( around 3 times ). but suddenly my child window hangs... ( browser is up but loading...) any ideas?Alvin ShihSoftware DeveloperMCP MCTS MCPD can u give more detail??? i don't think that child window hanged... there shoud be any other problem. did u write some more javascript in child or parent window??? if yes then send it too... Looks like the same old memory leak is...

closed window with 4 open tabs
Name: Scott Stringe Email: scottsatucardotedu Product: Firefox Summary: closed window with 4 open tabs - no warning message, it closed and left this error page... / Great job on 3.5 folks!!! really like the moving tabs and windows :- Comments: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@coolpreviews.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information abou...

superreview granted: [Bug 348183] scenario where clicking cancel in the "closing window with <n> tabs open" prompt closes the window, instead of keeping it open : [Attachment 233097] alternative, low
Brian Ryner <bryner@gmail.com> has granted Seth Spitzer [:ss] <sspitzer@mozilla.com>'s request for superreview: Bug 348183: scenario where clicking cancel in the "closing window with <n> tabs open" prompt closes the window, instead of keeping it open https://bugzilla.mozilla.org/show_bug.cgi?id=348183 Attachment 233097: alternative, low-risk patch until everything is sorted out https://bugzilla.mozilla.org/attachment.cgi?id=233097&action=edit ...

superreview requested: [Bug 348183] scenario where clicking cancel in the "closing window with <n> tabs open" prompt closes the window, instead of keeing it open : [Attachment 233097] low risk patch u
Seth Spitzer [:ss] <sspitzer@mozilla.com> has asked Brian Ryner <bryner@gmail.com> for superreview: Bug 348183: scenario where clicking cancel in the "closing window with <n> tabs open" prompt closes the window, instead of keeing it open https://bugzilla.mozilla.org/show_bug.cgi?id=348183 Attachment 233097: low risk patch until everything is sorted out https://bugzilla.mozilla.org/attachment.cgi?id=233097&action=edit ------- Additional Comments from Seth Spitzer [:ss] <sspitzer@mozilla.com> I'm still nervous about changing nsGlobalWindow.cp...

superreview denied: [Bug 241972] new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins : [Attachment 225651] check that session history is em
Darin Fisher (Google) <darin@meer.net> has denied Marria Nazif <marria@gmail.com>'s request for superreview: Bug 241972: new window opened by window.open('xxx.exe') or target="_blank" isn't closed automatically when a download begins https://bugzilla.mozilla.org/show_bug.cgi?id=241972 Attachment 225651: check that session history is empty https://bugzilla.mozilla.org/attachment.cgi?id=225651&action=edit ------- Additional Comments from Darin Fisher (Google) <darin@meer.net> Marria and I discussed this today. She's got a much bett...

superreview granted: [Bug 263844] Javascript window.close() on popup not working when popup is opened in tab : [Attachment 162257] set opener on opened windows diverted into tabs
Boris Zbarsky <bzbarsky@mit.edu> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 263844: Javascript window.close() on popup not working when popup is opened in tab https://bugzilla.mozilla.org/show_bug.cgi?id=263844 Attachment 162257: set opener on opened windows diverted into tabs https://bugzilla.mozilla.org/attachment.cgi?id=162257&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> r+sr=bzbarsky. Dan, thanks for doing this! I really wish we could factor some of this code that's being copied f...

Is there a way to close all windows you've opened from your application when the main window is closed?
My main application window opens a few additional windows with javascript. I'd like to close all of them when the main window is closed if they haven't already been closed by the user. Is there a way to do that? Thanks! Hello I handle closing a single window in my apps by declaring a javascript variable that will point to the open window var NewWindow; then set it if (NewWindow!=null)NewWindow.close(); NewWindow=window.open(parameters); set up the windows unload event to a function such as "destroypage" /* ****************************...

How to close all windows that open with command "open" except the first window?
Hi, I build an application with login and users manager. After validate login, the user can open different windows (opensheet & open). My problem appears when this user use my logoff : I can easly close all sheets but I can�t close the window that open with the command "open(...)". Are there a command (or other) to obtain the open window? Maybe that do I must work with a window�s array? What do you think? All solutions are welcome! Thanx in advance Chris M. Generally speaking, the parent of windows opened with Open() is the MDI frame, so if you...

window.open or window.close bug?
just want to ask, do javascript window.open() or window.close() have a bug? I'm using them for a popup that would self-close after 2 seconds. It works fine, but there are times, though very very few,  that when the popup window closes, the browser crashes, closes the opener too. thanks in advance.  I have never seen that, are you sure thats the only code executing at the time? Can you post the code? What browser causes the problem, did you try another browser.CheersAlMy BlogMapStats.NETPlease click on 'Mark as Answer' if this post answered your question! I ...

window.open and window.opener
Sorry for a really dumb post. I am not a scripting person... I find the whole thing a bit strange really with losely coupled types ect...Anyway, I am putting together a ASP.NET v2 application. One of the pages I am planning on implementing a link to open a pop-up window. In this popup window, the user will select the location of somthing, the window close and the value returned back to one of the parent browsers controls. I know this is not rocket science and I have done endless searches to try and find the answer. I am loading up the page and passing in the ClientID of the control I wish to...

Web resources about - window.opener.closed return an permission denied error when opener window is closed. - asp.net.client-side

Permission - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Facebook Tests Allowing Users To Start Games Instantly, Bypass Permissions Dialog
Facebook game developers Zynga , Kixeye , and Electronic Arts reached agreements with Facebook to test a new “start now” feature, that allows ...

Why is the Messenger app requesting permission to access features on my Android phone or tablet? - Facebook-Hilfebereich ...
If you install the Messenger app on your Android, your phone or tablet should let you know that the app is asking for your permission to access... ...

Permissions Reference - Facebook-Entwickler
When a user authenticates your application, by default, your app gets the ability to read only the u...

Facebook tests ‘start now’ option to allow users to begin playing games without authorizing permissions ...
Some Facebook canvas games are testing a new “start now” function to let users begin playing games immediately without the roadblock of a permissions ...

Davies McDonalds Happy Meal Project- all photos ©Sally Davies- use with permission only - an album on ...
View the album on Flickr. Flickr logo. If you click it, you'll go home Sign Up Explore Recent Photos The Commons 20under20 Galleries World Map ...

OOPS: without Permission, Paul Ryan and Family Show Up Washing Clean Dishes at Ohio Soup Kitchen - YouTube ...
The head of a charity in Ohio is not pleased with Paul Ryan's photo op at a soup kitchen in Ohio, saying that the Romney campaign "ramrodded ...

Arafat's widow grants permission for Swiss lab to test poisoning theory
The Palestinian Authority also approved the probe, which was requested by Palestinian president Mahmoud Abbas after a media investigation found ...

LeBron James sought sons' permission before his return to Ohio
Before LeBron James could return home to the Cavaliers, he first had to clear it with his children.

Jacqui Lambie shares another misappropriated image without permission
Senator Jacqui Lambie has been criticised for sharing a heavily altered Canberra Times cartoon to suit her own political campaign.

Resources last updated: 1/14/2016 11:14:19 PM