Typically, I utilize the colorbox tool to open "popup windows" on my page and everything works smoothly. However, in my latest project, things are a bit different as I am using js/ajax/dom to dynamically create my objects in the handleRequestStateChange() function.
After importing js, jquery, and css for colorbox, at the head of my js page, I include:
$(document).ready(function () {
$(window).scroll(function () {
//oP1 = document.createTextNode(posizione_menu.offsetTop);
//divIpt.appendChild(oMtx1);
$(".divHcss").css("position", "fixed").css("top", "0px").css("z-index", "999");
});
//Examples of how to assign the Colorbox event to elements
$(".group1").colorbox({rel:'group1'});
$(".group2").colorbox({rel:'group2', transition:"fade"});
$(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
$(".group4").colorbox({rel:'group4', slideshow:true});
$(".ajax").colorbox();
$(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:390});
$(".vimeo").colorbox({iframe:true, innerWidth:500, innerHeight:409});
$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
$(".inline").colorbox({inline:true, width:"50%"});
$(".callbacks").colorbox({
onOpen:function(){ alert('onOpen: colorbox is about to open'); },
onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
});
$('.non-retina').colorbox({rel:'group5', transition:'none'})
$('.retina').colorbox({rel:'group5', transition:'none', retinaImage:true, retinaUrl:true});
//Example of preserving a JavaScript event for inline calls.
$("#click").click(function(){
$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
return false;
});
});
Then, in the handleRequestStateChange(), I create an 'a' element and assign it to a div:
var a = createElement('a');
//a.style.display = "block";
a.setAttribute('class','iframe');
a.setAttribute('href',"php/whois.php?P1="+oStxt.value);
var divIp3 = createElement('div', 'divIp3', 'divIp3css');
var divIp31 = createElement('div', 'divIp31', 'divIp31css');
divIp3.appendChild(divIp31);
divIp3.appendChild(a);
a.appendChild(divIp31);
The divIp31 becomes linkable, but when clicked, the href opens the page in a normal browser tab instead of utilizing the attribute class for colorbox. Any ideas on how to resolve this?
Thank you in advance.
AM