phpknight Posted August 3, 2009 Share Posted August 3, 2009 I'm changing the background image with javascript. This works fine in Firefox, but IE doesn't change anything. I've tried multiple formats for the url. I also changed the code so that it changed the background-color instead. That worked. Is there anything special I have to do to get IE to change the background-image? Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/ Share on other sites More sharing options...
mikesta707 Posted August 3, 2009 Share Posted August 3, 2009 what does your current code look like? Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890015 Share on other sites More sharing options...
phpknight Posted August 3, 2009 Author Share Posted August 3, 2009 In the html, I have a div: <div id='VpcCanvas' style='background-image:url(blank.png);'> </div> Then when you click a button, it is supposed to just switch it to blank2.png. document.getElementById('VpcCanvas').style.backgroundImage=responseText2; //this is blank2.png One image is a slash, and the other is an X. So, when you click, one slash becomes an X> Everything works just fine in Firefox. I've tried url with no quotes, double-quotes, and single quotes. I've also tried full paths. No luck in IE. If I get rid of the background image and do a background color changing with white to blue, it works. Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890045 Share on other sites More sharing options...
phpknight Posted August 3, 2009 Author Share Posted August 3, 2009 Also, if I put a dummy alert box after, it shows in FireFox, but not in IE. It's like it chokes on the assignment, but I can't see anything wrong with it -- even from examples on other sites. Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890048 Share on other sites More sharing options...
mikesta707 Posted August 3, 2009 Share Posted August 3, 2009 try document.getElementById('VpcCanvas').style.backgroundImage="url(responseText2)"; //this is blank2.png remember when altering the styles of something you have to set the specific style attribute with correct CSS syntax Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890049 Share on other sites More sharing options...
phpknight Posted August 3, 2009 Author Share Posted August 3, 2009 Okay, I got it to work by putting a doctype and validating the html. I must have had a bug in there somewhere. I will incorporate your suggestion, too. Thanks! Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890069 Share on other sites More sharing options...
phpknight Posted August 3, 2009 Author Share Posted August 3, 2009 Ahhh. That was Firefox. Still working on it. Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890075 Share on other sites More sharing options...
phpknight Posted August 3, 2009 Author Share Posted August 3, 2009 On the above when I say it is blank2.png that is url(responseText2) as you advised. I don't put the quotes around it, though, because then it doesn't work in either browser. Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890082 Share on other sites More sharing options...
phpknight Posted August 3, 2009 Author Share Posted August 3, 2009 I finally got it to work in FireFix, IE, and Opera by using this instead: document.getElementById('VpcCanvas').style.background="url(responseText2)"; I'm not sure why background works instead of backgroundImage. Link to comment https://forums.phpfreaks.com/topic/168700-changing-background-image-in-ie/#findComment-890119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.