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" Quote Link to comment 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')"; } } Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.