PDA

View Full Version : Lightbox Viewer v2.03a



nfinity
04-16-2008, 03:51 PM
When I hard code a link, the lightbox works just fine:

<a href="http://www.harpandharptrading.com/images/tractors/6640ford.jpg" rel="lightbox[trac1]" title="my caption">image #1</a>

But, I need to create the links dynamically using javascript which I did with the following code:

var link = document.createElement("a");

link.href = "images/tractors/6640ford.jpg";
link.rel = "lightbox[trac1]";
link.title = "my caption";
link.innerHTML = "image1";

The link appears and when I look at it with firebug, it looks the same as the one I hard coded. But, when i click the link it takes me to a new page with just the image on it like it would if I typed in the url to the image.

Can someone help please?
http://www.dynamicdrive.com/dynamicindex4/lightbox2/index.htm

ddadmin
04-17-2008, 03:51 AM
Lightbox is automatically initialized when the page first loads. If you're adding lightbox specific links dynamically, most likely they will not be parsed due to the timing of the former versus the later. After you've added the links dynamically to the page, try calling:


myLightbox = new Lightbox();

at the end of your code again to reinitialize Lightbox.

nfinity
04-17-2008, 07:11 PM
Hi, and thanks for the reply.

I tried putting
myLightbox = new Lightbox(); in my function where I am creating the links. I dont get any errors but when i click the link, it isnt doing right.

I also put it at the end of my javascript code and it gives me an error that says objBody has no properties and objBody.appendChild(objOverlay);

Can you think of why this isn't working?