2

In a php script, at certain point I need to show up a GreyBox popup:

<?php
    if ($myvar==''){
?>
    <script>
    // I need to show mypage.php in a GreyBox popup when in here
   GB_showCenter('Title', 'mypage.php' , 300, 620);

    </script>
<?php
    }
?>

The code above shows the popup when $myvar is empty but mypage.php never loads, the loading gif never stops turning and Firebug shows a "GB null" error pointing to loader_frame.html.

I also tried:

GB_show("Title", "mypage.php");

but same problem.

If I do:

<a href="mypage.php" onclick="return GB_showCenter('Title', this.href , 300, 620)">Click here</a>

somewhere in the page I have the popup with no problems so I know the files are correctly installed.

What am I doing wrong?

Thanks a lot!

user712027
  • 572
  • 6
  • 9
  • 22

1 Answers1

1

I know this is ugly, but can you try if it works:

<?php
    if ($myvar==''){
?>
    <script>

        pathArr = window.location.pathname.split('/');
        path = window.location.protocol + "//" + window.location.host+"/";
        for (i=1;i<pathArr.length-1;i++) path += pathArr[i]+"/";

        GB_showCenter('Title', path+'mypage.php' , 300, 620);

    </script>
<?php
    }
?>

OK - another one (even uglier):

<?php
    if ($myvar==''){
?>
    <a href="mypage.php" onclick="return GB_showCenter('Title', this.href , 300, 620)" style="display: none;" id="myGreyBoxLink">Open GrayBox Window</a>
    <script>
        document.getElementById('myGreyBoxLink').onclick();
    </script>
<?php
    }
?>
Alexander Ivanov
  • 717
  • 4
  • 16
  • Thanks Alexander, but it is not about using a link. In fact, the link structure works ok when tried it in the same page. The problem comes when trying to fire the window from an if statement. Thanks again – user712027 Apr 29 '11 at 07:43
  • Well my last update hides the link and clicks it with JS - if that works I can make you an implementation where it will be done in DOM and no unnecessary HTML is going to pollute your code. – Alexander Ivanov Apr 29 '11 at 08:51