Colorbox with Javascript
For the past 6 months at least, I’ve had varied versions of ‘JavaScript embedded into Colorbox’ as a search term that has led to my website and after numerous occasions of useless dead ends on my site, I thought that I’d go ahead and write a post about a very basic way to get this done.
The easiest way to call a Colorbox is with the following code:
$(“idColorboxLink”).colorbox({href:”/link/”, open:true});
Visit the demo page for Colorbox to see other ways to open it.
There are exactly 5 ways that you can place your JavaScript so that your colorbox content will be affected by it.
onOpen (Before Colorbox opens)
onLoad (While Colorbox is opening)
onComplete (Content is displayed in the Colorbox)
onCleanup (While Colorbox is closing)
onClosed (Colorbox is closed)
Then you just enter them into the code as follows:
$(“idColorboxLink”).colorbox({href:”/link/”, onOpen:function(){}, onLoad:function(){}, onComplete:function(){}, onCleanup:function(){}, onClosed:function(){}, open:true});
If you had a function like…fillField, you could just call it like this:
$(“idColorboxLink”).colorbox({href:”/link/”, onComplete:function(){fillField()}, open:true});
This probably could have been much more elaborate, but I’m more a use it to learn it kind of person and I thought that this might at least provide an idea of what to do if nothing else for those who are searching for this.
Have a great day.