测试当前页面是否在 Shadowbox 内? (这样我就可以关闭阴影盒并在主窗口中重新打开该页面)

发布于 2024-09-03 04:40:02 字数 477 浏览 4 评论 0原文

我的网站中有几个页面在 Shadowbox 窗口而不是主窗口中打开。我的问题是,如果用户会话过期,那么用户单击在影子盒中打开的链接之一,他们将被重定向到影子盒内的登录页面,这是我不想要的。我一直在试图想出处理这个问题的最佳方法 - 我想到的一种方法,似乎有点笨拙,是在登录页面上测试我们是否在影子盒中,如果我们关闭它,并将父窗口重定向到登录页面。

a) 这看起来是一个明智的计划吗?我将以下内容添加到我的登录页面,该页面有效:

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

但我必须等待影子盒完成加载页面,然后重定向。所以它有效,但就像我说的有点笨拙。有更好的方法吗?

感谢任何建议 - 最大

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

染火枫林 2024-09-10 04:40:02

我知道这篇文章很旧,但我最近不得不解决同样的挑战,并认为其他人可能会在这篇文章中寻找答案。

上面给出的答案很好,但没有很好地回答原来的问题,这并不是真正的“如何检查页面是否在影子盒中?”,而是“如何避免页面在影子盒中加载,然后Shadowbox 关闭后再次加载?”

这是我所做的:

检查活动会话的代码转发到注销页面,该页面清除任何剩余的会话值并将用户发送到登录页面。我将以下代码添加到 onload 函数中的注销页面:

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

现在,当调用注销页面时,它会在浏览器获取任何登录页面视图之前清除影子框。效果很好。希望这可以帮助别人。

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.

许一世地老天荒 2024-09-10 04:40:02

使用 isOpen()。

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

尝试 this.link.baseURI 来查看它是否与 window.location 相同(如果您想访问 Shadowbox 内的浏览器位置)。

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.

年华零落成诗 2024-09-10 04:40:02

在登录页面尝试以下操作:

var Shadowbox = window.parent.Shadowbox;

然后检查 Shadowbox 是否未定义。

Try this on the login page:

var Shadowbox = window.parent.Shadowbox;

Then check to see if Shadowbox is undefined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文