kev wood Posted April 29, 2008 Share Posted April 29, 2008 i need a function that will swap images on a page when an iframe is loaded onto it. i have tried to do this my self and have tried a few different methods but all to no avail i am still stuck. i have tried to do it using the following code but i had no joy could anyone show me where the code is wrong or point me in the direction of a good tutorial. function changeImage() { if (document.getElementById) { document.getElementById("image").src="images/home_title.jpg"; } else if (document.all) { document.all["image"].src="images/home_title.jpg"; } else if (document.layers) { document.layers["image"].src="images/home_title.jpg"; } } inside the body tag onload="changeImage()" the image that i am trying to swap is a background image from a table and the code for this is id="image" background="images/commissioning_title.jpg" Link to comment https://forums.phpfreaks.com/topic/103379-background-image-swap/ Share on other sites More sharing options...
rhodesa Posted April 29, 2008 Share Posted April 29, 2008 <table id="image" style="background:url('images/commissioning_title.jpg');"> function changeImage() { if (document.getElementById) { document.getElementById("image").style.background = "url('images/home_title.jpg')"; }else if (document.all) { document.all["image"].style.background = "url('images/home_title.jpg')"; }else if (document.layers) { document.layers["image"].style.background = "url('images/home_title.jpg')"; } } Link to comment https://forums.phpfreaks.com/topic/103379-background-image-swap/#findComment-529732 Share on other sites More sharing options...
kev wood Posted May 6, 2008 Author Share Posted May 6, 2008 thanks for the reply i ended up doing it using iframes and changing the images with a button click. that code will come in useful though. thanks again Link to comment https://forums.phpfreaks.com/topic/103379-background-image-swap/#findComment-534212 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.