GreyBox:从函数内部调用弹出窗口

时间:2011-04-27 08:04:07

标签: php javascript popup modal-dialog greybox

在php脚本中,在某些时候我需要显示一个GreyBox弹出窗口:

<?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
    }
?>

上面的代码显示了$ myvar为空但是mypage.php永远不会加载的弹出窗口,加载gif永远不会停止转动,Firebug显示指向loader_frame.html的“GB null”错误。

我也尝试过:

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

但同样的问题。

如果我这样做:

<a href="mypage.php" onclick="return GB_showCenter('Title', this.href , 300, 620)">Click here</a>
在页面的某个地方,我有弹出窗口没有问题所以我知道文件已正确安装。

我做错了什么?

非常感谢!

1 个答案:

答案 0 :(得分:1)

我知道这很难看,但是你可以试试它是否有效:

<?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
    }
?>

好的 - 另一个(甚至更丑):

<?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
    }
?>
相关问题