【问题标题】:GreyBox: calling the popup from inside a functionGreyBox:从函数内部调用弹出窗口
【发布时间】:2011-04-27 08:04:06
【问题描述】:

在 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>

在页面的某处,我的弹出窗口没有问题,因此我知道文件已正确安装。

我做错了什么?

非常感谢!

【问题讨论】:

  • 尝试使用完整网址GB_showCenter('Title', 'http://domain.com/mypage.php' , 300, 620);
  • 很抱歉,只是为了确保...您是否已将功能 GB_showCenter 包含在您的脑海中?
  • 是的,onclick 结构正在使用它,并且在测试时运行良好。谢谢

标签: php javascript popup modal-dialog greybox


【解决方案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
    }
?>

【讨论】:

  • 感谢 Alexander,但这与使用链接无关。实际上,在同一页面中尝试链接结构时可以正常工作。当试图从 if 语句中触发窗口时,问题就出现了。再次感谢
  • 好吧,我的最后一次更新隐藏了链接并使用 JS 进行点击 - 如果可行,我可以为您提供一个实现,它将在 DOM 中完成,并且没有不必要的 HTML 会污染您的代码。跨度>
猜你喜欢
  • 1970-01-01
  • 2021-01-08
  • 2011-07-23
  • 1970-01-01
  • 1970-01-01
  • 2014-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多