15

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

anyone know how I can do this?

thanks.

DemonXTC
  • 151
  • 1
  • 1
  • 3

4 Answers4

19

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()"/>
Jack
  • 9,150
  • 3
  • 26
  • 33
5

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>
Jack
  • 9,150
  • 3
  • 26
  • 33
jeremysawesome
  • 6,457
  • 3
  • 32
  • 35
2

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>
Adam Luz
  • 29
  • 1
  • It seems that this isn't working for me anymore. I don't know if it was from a Colorbox update or a jquery update. – Keith Feb 19 '13 at 20:31
0
$("tr").click(function () { 

    $.colorbox({width:"900px", height:"600px", iframe:true, href:"http://www.google.com"});

});
nixis
  • 492
  • 5
  • 10