Detect if page is in facebox

5 views
Skip to first unread message

wakey

unread,
Jul 2, 2009, 5:31:54 AM7/2/09
to facebox
I was wondering if it is possible to automatically detect whether a
page is loaded within facebox and if it isn't, redirect to another
page?

I just can't think how to go about this.

Thanks for any help.

Tom

Jade

unread,
Jul 3, 2009, 12:33:56 AM7/3/09
to facebox
I can think of 2 ways to do this.

The most basic way would be to attach a GET variable at the end of any
link being called via facebox. For example a link might look like
this:

<a href="/path_to_page.php?facebox=true" rel="facebox">Link</a>

Then your page just needs to check if the $_GET['facebox'] is set and
if it is true.

The second one uses php so it may not be applicable to your case, but
you can do something like this:

if('XMLHttpRequest' == @$_SERVER['HTTP_X_REQUESTED_WITH'])
{
// show facebox
}
else
{
// show full page
}

the XMLHttpRequest is assigned for all ajax based calls. Since facebox
requests the page via xmlhttp this var will be assigned. Keep in mind
that any ajax request will assign it, not only facebox.

Hope this helps.

wakey

unread,
Jul 3, 2009, 3:32:32 AM7/3/09
to facebox
Hi Jade,

Thank you for your help, I will give one of those a try. Much
appreciated :)

Tom
Reply all
Reply to author
Forward
0 new messages