2013-02-08 31 views
5

Tôi đã sử dụng hộp đèn jQuery hộp đèn màu cho hộp đèn của tôi. Nhưng trong đó ta nên bấm vào nút. Tôi muốn tự động bật lên bất cứ khi nào cửa sổ được tải.Mở jQuery ColorBox tự động khi tải trang

Mã của tôi cho hộp đèn là

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
     <script src="../jquery.colorbox.js"></script> 
     <script> 
      $(document).ready(function(){ 
       $(".ajax").colorbox(); 
      }); 
     </script> 
    </head> 
    <body> 

     <h2>Other Content Types</h2> 
     <p><a class='ajax' href="../content/daisy.jpg" title="Homer Defined">Outside HTML (Ajax)</a></p> 
</html> 

Bây giờ tôi muốn một popup tự động khi cửa sổ được tải.

Trả lời

11

Với phiên bản mới nhất của ColorBox, bạn sử dụng $.colorbox({inline:true, href:".ajax"});

bản demo làm việc: http://jsfiddle.net/34v22/

Tôi cũng dọn dẹp mã của bạn một chút:

<!doctype html> 
<head> 
    <title>My Automatic ColorBox</title> 
    <link rel="stylesheet" type="text/css" href="../link/to/jquery.colorbox.css"> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
    <script type="text/javascript" src="../jquery.colorbox.js"></script> 
    <script>$(document).ready(function(){$.colorbox({inline:true, href:".ajax"});});</script> 
</head> 
<body> 
    <h2>Other Content Types</h2> 
    <div class='ajax' style='display:none'><a href="../content/daisy.jpg" title="Homer Defined">Outside HTML (Ajax)</a></div> 
</body> 
0

Nếu bạn thích, bạn có thể thêm html của bạn trực tiếp trong cuộc gọi jQuery

(function($){ 
    $(document).ready(function() { 
     $.colorbox({innerWidth:420,innerHeight:315,html:'<iframe width=420 height=315 src=http://www.youtube.com/embed/eh-0knDpn5g frameborder=0 allowfullscreen></iframe>'}); 
    }); 
})(jQuery); 
1

Nó hoạt động nhưng tôi không thể nhấp vào trang iframe. Tôi đã đặt một biểu mẫu trong khung nội tuyến.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> 
</script> 
<script type="text/javascript" src="js/jquery.colorbox.js"></script> 
<script>$(document).ready(function(){$.colorbox({inline:true, href:".ajax"});}); 
</script> 

<script> 
(function($){ 
     $(document).ready(function() { 
      $.colorbox({innerWidth:600,innerHeight:500,html:'<iframe width=600 height=500 
        src=masson-form.html> </iframe>'}); 
       }); 
     })(jQuery); 
</script> 
Các vấn đề liên quan