简体   繁体   English

Fancybox jQuery /页面加载时关闭框

[英]Fancybox jQuery / Close box when page load

Inside a fancybox, I want to execute some PHP, then make the box closed automatically. 在一个花哨的盒子里,我想执行一些PHP,然后使盒子自动关闭。

Here's what's in the FAQ 这是常见问题解答中的内容

  1. How can I close FancyBox from other element? 如何关闭其他元素的FancyBox? ? Just call $.fancybox.close() on your onClick event 只需在onClick事件上调用$ .fancybox.close()

Where to put this in my page ? 将此放置在我的页面中?

This is what I made (not working) : 这是我做的(不起作用):

    <?php   ... (my php)      ?>

<!doctype html>

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-15">
</head>

  <body onload="$.fancybox.close();">
  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
  <link rel="stylesheet" href="http://www.fizzyexpress.pro/admin/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
  <script type="text/javascript" src="http://www.fizzyexpress.pro/admin/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>  

</body>

Sorry, I'm newbie ... Thanks for any help ! 抱歉,我是新手,谢谢您的帮助!

If you need to just close it when page is loaded, you can use document.ready() like below: 如果只需要在加载页面时将其关闭,则可以使用document.ready()如下所示:

$( document ).ready(function() {
    $.fancybox.close();
});

But if you need to run a PHP script, and then close fancybox, you must make an AJAX call, then call $fancybox.close() into success . 但是,如果需要运行PHP脚本,然后关闭fancybox,则必须进行AJAX调用,然后调用$fancybox.close() success See JQuery.ajax() 参见JQuery.ajax()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM