Jump to content

[SOLVED] Style change


hellouthere

Recommended Posts

I'm trying to change a style using javascript, its all working ok except changing a background image in ie6...

 

hellouthere.homelinux.com/eanda

 

The site uses AJAX to navigate, on each page the image below the logo should be updated, this works well in FF IE7 and Safari but previous to IE7 all the AJAX works except the updating the image on each page. I'm using AJAx but I think this is a pure javascript problem as everything works fine in other browsers.

 

I know IE6 is a pain but is there any workaround to get this to work?

 

This is the function to change the text and image for each page... it updates the background image of the pic1 div and adds the correct text to the required div (objID).

 

function navto(serverPage, objID) {

document.getElementById("pic1").style.backgroundImage = "url(images/" + serverPage + ".png)";

var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage + ".inc");

xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		obj.innerHTML = xmlhttp.responseText;
	}
}
xmlhttp.send(null);
}

 

When the homepage opens it uses this function to load the image and text and that works fine, its when it comes to changing to other pages that it fails...

 

Thanks in advance

 

Link to comment
Share on other sites

i was able to get it working if I opened the image ahead of time in my browser...try preloading the image:

function navto(serverPage, objID) {
var img = new Image();
img.src = "images/" + serverPage + ".png";
document.getElementById("pic1").style.backgroundImage = "url(images/" + serverPage + ".png)";


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.