It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Gallery

Log In Sponsors
Board index Programming JavaScript Forum

Image Gallery Help - IE issue

Image Gallery Help - IE issue

Postby bigdork817 on Thu Apr 10, 2008 1:15 am

I recently used javascript to create my first image gallery in a website. It looks great in Firefox, but fails miserably in IE. Instead of loading the image onto the same page and displaying the description below, it simply follows the link to each image, which displays only the image on a white background.

I relied heavily on tutorials from the book DOM scripting by Jeremy Keith to create the gallery. And the website in question may be viewed here:
http://www.lovehippiechic.com/necklaces.html

Below I am attaching the javascript code I used on the website

Code: Select all
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function preparePlaceholder() {
  if (!document.createElement) return false;
  if (!document.createTextNode) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  var placeholder = document.createElement("img");
  placeholder.setAttribute("id","placeholder");
  placeholder.setAttribute("src","i/images/placeholder.gif");
  placeholder.setAttribute("alt","my image gallery");
  var description = document.createElement("p");
  description.setAttribute("id","description");
  var desctext = document.createTextNode("Choose an image");
  description.appendChild(desctext);
  var feature = document.getElementById("feature");
  insertAfter(placeholder,feature);
  insertAfter(description,placeholder);
}

function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("imagegallery")) return false;
  var gallery = document.getElementById("imagegallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
   }
    links[i].onkeypress = links[i].onclick;
  }
}

function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  placeholder.setAttribute("src",source);
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var description = document.getElementById("description");
  if (description.firstChild.nodeType == 3) {
    description.firstChild.nodeValue = text;
  }
  return false;
}

addLoadEvent(preparePlaceholder);
addLoadEvent(prepareGallery);


Any suggestions on how I might fix this gallery to work properly in all newer browsers would be greatly appreciated. Thanks for your time.

Brian[/url]
bigdork817
 
Posts: 0
Joined: Thu Apr 10, 2008 1:02 am

Who is online

Users browsing this forum: No registered users and 5 guests