Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine if page is being viewed through lightbox?

I have several sites I'm working on that are loading sub-pages via lightbox. The actual content is being found by Google, but the pages are hideous as they aren't meant to load all the headers and whatnot - this is content intended for lightbox delivery (ajax, fancybox).

In PHP, or javascript if necessary, how might I determine if the content is being viewed in a lightbox or not? Would be nice to throw up a "view the original page" link or something.

like image 323
GhostToast Avatar asked Apr 23 '12 16:04

GhostToast


3 Answers

lightbox like every other similar lib use AJAX for pulling content ... am not sure sure if you can detect if it is a standard jquery or moottools or lightbox because they all you the same technology

What you can do is detect if your page is been called via AJAX

function isAjax() {
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest");
}

if(isAjax())
{
    die("Don't Use AJAX");
}
else
{
    echo "WELCOME" ;
}
like image 130
Baba Avatar answered Nov 18 '22 08:11

Baba


Lightboxes often use iframes to display external pages. If this is the case (you can inspect the Lightbox using Firebug to check this), you can use window.top on JavaScript to check this.

if (window.top.location != window.location) {
    //this page is inside a frame or iframe
}
like image 45
alganet Avatar answered Nov 18 '22 09:11

alganet


If you are using the latest version of fancyBox with the default options then this trick should work -

<?php echo (isset($_SERVER['HTTP_X_FANCYBOX']) && $_SERVER['HTTP_X_FANCYBOX']) ? 'is fancyBox' : 'is not fancyBox' ?>
like image 1
Janis Avatar answered Nov 18 '22 09:11

Janis