Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call jQuery colorbox with javascript onClick event instead of a link?

I want to call colorbox using javascript rather than a href link?

anyone know how I can do this?

thanks.

like image 678
DemonXTC Avatar asked Dec 10 '10 04:12

DemonXTC


3 Answers

The previous examples didn't work for me, but using the same idea, this does work:

<script>
function lightbox(){    
  $.colorbox({width:"80%", height:"80%", iframe:true, href:"/pagetoopen.html"});
}
</script>

<input type="button" value="open the box" onClick="lightbox()"/>
like image 87
Memohotel Trip Organizer Avatar answered Nov 18 '22 11:11

Memohotel Trip Organizer


This is off the top of my head. But I believe you could do something like this:

<script type="text/javascript">
function call_cbox()
{
   jQuery.colorbox({html:'<p>Hi There I was instantiated onclick!</p>'});
}
</script>
<a href="#" onclick="call_cbox(); return false;">Give me a colorbox... NOW! And don't forget the color.</a>
like image 28
jeremysawesome Avatar answered Nov 18 '22 13:11

jeremysawesome


A mix of the two answers above worked for me:

<script>
function call_cbox()
{
jQuery().colorbox({width:"900px", height:"600px", iframe:true, href:"/newsletter.html"});
}
</script>
like image 2
Adam Luz Avatar answered Nov 18 '22 11:11

Adam Luz