测试当前页面是否在 Shadowbox 内? (这样我就可以关闭阴影盒并在主窗口中重新打开该页面)
我的网站中有几个页面在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这篇文章很旧,但我最近不得不解决同样的挑战,并认为其他人可能会在这篇文章中寻找答案。
上面给出的答案很好,但没有很好地回答原来的问题,这并不是真正的“如何检查页面是否在影子盒中?”,而是“如何避免页面在影子盒中加载,然后Shadowbox 关闭后再次加载?”
这是我所做的:
检查活动会话的代码转发到注销页面,该页面清除任何剩余的会话值并将用户发送到登录页面。我将以下代码添加到 onload 函数中的注销页面:
现在,当调用注销页面时,它会在浏览器获取任何登录页面视图之前清除影子框。效果很好。希望这可以帮助别人。
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:
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.
使用 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 aswindow.location
if you want to access the browser location inside the shadowbox.在登录页面尝试以下操作:
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.