Hi,

How do i open the colorbox on load or on a condition for example open a popup if a cookie is not set.

Thanks,

Comments

knigh7’s picture

Never mind

just in case someone else needs it, here is how you can open colorbox using a script

(function ($) { $(document).ready(function(){ $.fn.colorbox({href:'http://www.google.com', open:true, iframe:true, width:500, height:500}); }); }(jQuery));
knigh7’s picture

Status: Active » Closed (fixed)
Anderskj’s picture

I have used 5 hours now to get something like this to work:

<script type="text/javascript" >
   $(document).ready(function() {		
       $.fn.colorbox({iframe:true,href:'/node/117', width:300px, height:550px, open:true});
    });
</script>

This is placed inside and on the same page is a working link (when clicked):

<a href="/partner-request?&amp;width=243&amp;height=490&amp;iframe=true" class="colorbox-load init-colorbox-load-processed-processed cboxElement" id="popup-form">Become a partner</a>

This is the page: http://acmarine.dk/partners-usa (click the "Become a parther link" to see the colorbox).
I don't know how to open the colorbox (same as clicking the link) on page load. Beleive I have now tried "everything". Where do I put the code in #1?

knigh7’s picture

Here is my code, it works with Drupal 7, I have placed it just after the body tag

<script type="text/javascript">
(function ($) {

$(document).ready(function(){
	$.fn.colorbox({href:'/node/54', open:true, iframe:true, width:817, height:500,overlayClose: false, escKey:false}
	);
}); 
}(jQuery));
</script>
cruze72’s picture

I've put the code into my frontpage.tpl.php and #4 works like a charm for me - thanks.

BUT how can i adapt the code to only load once and not every time the page is loaded.

Much appreciated

knigh7’s picture

Hmm, you can set a cookie to make it run once, what you can do is set a cookie using javascript and do the whole logic in javascript or using php check if the cookie exists, if its not there then write the cookie and then using php echo the javascript code for the popup

mcfilms’s picture

Here is how someone did one-time only with lightbox. You can probably modify this for colorbox:

http://drupal.org/node/1005658#comment-4838222

pauleh’s picture

Here's how I did a colorbox popup for a disclaimer note for a specific node with a 'close box' link and a 'close/redirect' link.

1. Created a node specific template (see: http://robmalon.com/drupal-7-0-preprocess-page-templates-theme_hook_sugg...)

2. Above </head> in html--node--##.tpl.php

<script type="text/javascript">
	jQuery(document).ready(function(){
    jQuery.colorbox({href:'my.html', iframe:true, open:true, width:500, height:500})
    });
</script>

3. In 'my.html' there are two links

	<p><a onClick="parent.jQuery.colorbox.close()" href="javascript:;" >Close Popup</a></strong></p>
	<p><a onClick="window.parent.location = 'url';" href="javascript:;">Redirect to alternate page</a></p>
brandonc503’s picture

Issue summary: View changes

what if i dont need by cookie, i just want on page load, click the first image triggering colorbox