www.webdeveloper.com
Results 1 to 10 of 10

Thread: Access Denied when I access parent window for the second time

  1. #1
    Join Date
    Apr 2005
    Posts
    5

    Access Denied when I access parent window for the second time

    Hello,

    I recently encountered a javascript error problem. Basically the problem is like this:

    I want to display a html form in browser, this html contains an iframe. In Iframe, there is a link to launch a popup. In the popup html, there are two links. Click each link should display a html file in the base browser (at the top level).

    Now the problem is: the first time I click a link (any link) in the popup, it works as expected. But for the second time (without close the popup) I click the link (the same link or different link), I got a javascript error message "Access is Denied". Is it because the original window is gone after we loaded a different page in base browser?

    Any idea why this happens and how to achieve this?

    I am attaching all the html files in "iframe-error.zip". The base html is "base.html".

    I appreciate your help!
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2004
    Posts
    8,637
    In your popup window, are you using window.opener to access the original window? ...or, what?

  3. #3
    Join Date
    Apr 2005
    Posts
    5

    I am using window.opener.parent to access the original window

    I am using window.opener.parent to access the original window.

    If I click the link in popup window at first time, it works fine, but from the second time, it displayed the 'Access Denied' error message.

  4. #4
    Join Date
    Dec 2004
    Posts
    8,637
    OK, yes, the IFRAME is a window object. When you replace the parent document, you destroy that window object. Thus, the window.opener reference in the popup window is no longer valid.

  5. #5
    Join Date
    Apr 2005
    Posts
    5

    so is there any alternatives to achieve this?

    I want to keep the popup open all the time, and click different links in the popup to show different pages in the base browser.

    Is it even doable if IFRAME is involved?

  6. #6
    Join Date
    Dec 2004
    Posts
    8,637
    Well, each document that you load into the main window is going to have to re-establish the connection with the popup window. This can be accomplished by using the same window.open() specification for the window name that was used when the popup was first create. So, if the following was used the first time:

    window.open('...someURL...', 'MyWindow', '...optional features...');

    then the following is what you want to do from the new document when it loads into the main window:
    Code:
    winPtr = window.open('', 'MyWindow', '...optional features...');
    winPtr.opener = self;
    As strange as it may seem, using a zero-length string for the URL and giving a matching window name will re-create a pointer to that popup window. Then you can refresh the window.opener reference as shown above.

    Mind you, this means that you can't be using window.opener.parent.location... anymore. I recommend you change that to window.opener.top.location... as this will be a consistent reference to the topmost window in the browser no matter which way the window.opener reference is currently set.

    Get it?
    Last edited by phpnovice; 04-07-2005 at 02:45 PM.

  7. #7
    Join Date
    Apr 2005
    Posts
    5

    thanks a lot...

    Thanks a lot. I will try it out on my machine and see if it work.

    I really appreciate your help!

  8. #8
    Join Date
    Dec 2004
    Posts
    8,637

    Thumbs up You're welcome.

    Cheers.

  9. #9
    Join Date
    Apr 2005
    Posts
    5

    it works....

    Hi phpnovice,

    it works perfect. Looks like passing blank URL with the same popup name does re-establish the connection between the base window and the popup window

    Thanks a lot.

  10. #10
    Join Date
    Dec 2004
    Posts
    8,637

    Talking Was there any doubt?

    Cheers.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles