简体   繁体   中英

Test if current page is inside a shadowbox? (so i can close the shadowbox and reopen that page in the main window)

I have a couple of pages in my site which open in a shadowbox window rather than the main window. My problem is that if the user session expires, then the user clicks on one of the links that open in a shadowbox, they are redirected to the login page INSIDE THE SHADOWBOX, which i don't want. I've been trying to think of the best way to handle this - one way i thought of, which seems a bit clumsy tbh, was on the login page to test if we're in a shadowbox, and if we are then close it and redirect the parent window to the login page.

a) does this seem like a sensible plan? I added the following to my login page, which works:

  $(document).ready(function(){
    if(window.parent.location != window.location){
      window.parent.location.href = window.location;
    }
  }

but i have to wait for the shadowbox to finish loading the page and then redirect. So it's working but like i say a bit clumsy. Is there a nicer way?

grateful for any advice - max

I know this post is old but I had to address the same challenge recently and thought someone else might happen upon this post looking for an answer.

The answers given above are great, but do not answer well the original question, which wasn't really "How do I check if the page is in a shadowbox?", but "How do I avoid the page loading within a shadowbox and then loading again after the shadowbox is closed?"

Here is what I did:

The code that checks for the active session forwards to a logout page which clears any remaining session values and sends the user to the login page. I added the following code to the logout page within an onload function:

if (window.parent) {
    window.parent.location.replace('your-login-url');
} else {
    window.location.replace('your-login-url');
}

Now when the logout page is called, it clears the shadowbox before the browser ever gets any of the login page view. Works great. Hope this can help someone.

Use isOpen() .

http://www.shadowbox-js.com/api.html

Try this.link.baseURI to see if that is the same as window.location if you want to access the browser location inside the shadowbox.

Try this on the login page:

var Shadowbox = window.parent.Shadowbox;

Then check to see if Shadowbox is undefined.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM