June 4, 2012

Force lightbox to open in parent page php JavaScript

Question by user1434701

Yet another newbie asking for help.

I have a Main_index.php page. Multiple divs are loaded into this page and each div has a “More” information button. Each div is a template style and is completed with mysql data.

<div class="more"><a href="advert_details.php?advert_id=<?php print $advert_id?>"id="more<?php print $advert_id?>"><?php echo MORE ?></a></div>

Each “More” button brings up a new page “advert_details.php”, inside a lightbox. This is again a template style and loads details from mysql. The lightbox code is in the Main_index.php.

<script language="JavaScript" type="text/javascript">
$(document).ready(function()
        {
        $('a').filter(function() {
        return this.id.match(/more[0-9]/);
    }).fancybox({
        'overlayColor' : '#000',
        'overlayOpacity' : 0.1,
        'width' : 640,
        'height' : 940,
        'type' : 'iframe'
    });
});
</script>

If one of the “advert_details.php” pages is found by a search engine, when you click on the search result, the lightbox opens in a blank page.

Is there anything I can add, to force the “advert_details.php” page to open in the “main_index.php” page, making use of the lightbox JavaScript and showing the main site page?

I hope that I have explained this well, if not, please ask for more details.

Thanks

Peter

Answer by Starx

You can set a URL parameter which will be checked to include the advert_details.php in the main page.

Something like

if(isset($_GET['showDetails'])) {
   include "advert_details.php";
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!