Open jQuery Colorbox onLoad

April 7th, 2010 - Posted by Steve Marks to Javascript / jQuery, Web Development.

Open a jQuery colorbox with no user interaction

Update – 26th December 2010 (Credit to azrad)

Since writing this post it seems that ColorBox has been updated meaning the solution below is now longer needed. Simply using the latest version of colorbox will allow you to open the ColorBox onLoad.


I came across a scenario today where I needed to open the jQuery ColorBox as soon as the page loaded. After looking on the ColorBox website it read as follows:

And it can be called directly, without assignment to an element
Example: $.fn.colorbox({href:”thankyou.html”});

After attempting to add the above code to the onload event of the page nothing happened. No ColorBox, no errors, nothing. After a short while spent researching it appears that there is an extra parameter required called ‘open’ that, if set to TRUE, results in the ColorBox opening automatically with no input from the user. The resulting, and functioning, code now looked as follows:

<script type="text/javascript">
	$(document).ready(function() {
		$.fn.colorbox({href:"thankyou.html", open:true});
	});
</script>
This entry was posted on Wednesday, April 7th, 2010 at 8:26 pm by +Steve Marks and is filed under Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments...

Fear not, we won't publish this

Comments (31)

No comments have been left yet. Be the first