2013-02-08 18 views
5

Ich habe die Farbbox jQuery Leuchtkasten für meine Lightbox verwendet. Aber darin sollte man auf den Knopf klicken. Ich möchte automatisch Popup immer wenn das Fenster geladen wird.Öffnen Sie jQuery ColorBox automatisch beim Laden der Seite

Mein Code für Lichtbox ist

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

Jetzt möchte ich auf ein automatisches Popup, wenn das Fenster geladen wird.

Antwort

11

Mit der neuesten Version von ColorBox verwenden Sie $.colorbox({inline:true, href:".ajax"});

Arbeits Demo: http://jsfiddle.net/34v22/

ich auch Ihren Code ein wenig aufgeräumt:

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

Wenn Sie möchten, können Sie Ihre HTML direkt hinzufügen in der jQuery Anruf

(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

Es funktionierte, aber ich bin nicht in der Lage, auf zu klicken die Iframe-Seite. Ich habe ein Formular in den iFrame eingefügt.

<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> 
Verwandte Themen