| | |
Rollovers not working in FF/Chrome, but IE is okay.
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 5
Reputation:
Solved Threads: 0
I'm really new at JavaScript, but I thought an image map with rollover images would be a relatively basic feat...
I have a large map with hotspots over individual states. I want the user to hover over a hotspot and for the main image to change, displaying information for that particular state. I've tried code that other developers have sworn works in all browsers, but still can't get the same functionality in FF or Chrome as I do in IE.
The last thing I tried was ...
In the head tag...
And in the body...
Is anyone able to tell me what I'm doing wrong/missing?
Thank you very much in advance!
I have a large map with hotspots over individual states. I want the user to hover over a hotspot and for the main image to change, displaying information for that particular state. I've tried code that other developers have sworn works in all browsers, but still can't get the same functionality in FF or Chrome as I do in IE.
The last thing I tried was ...
In the head tag...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<SCRIPT language="javascript" type="text/javascript"> function swapImage(image) { var Map = (document.getElementById) ? document.getElementById('MapWest') : (document.images) ? document.images['MapWest'] : (document.all) ? document.all['MapWest'] : null; if(Map) Map.src = image; } </SCRIPT>
And in the body...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<img id="MapWest" src="images/map/MapWest_NowServing.png" alt="" name="MapWest" height="508" width="700" usemap="#MapWest_NowServing" border="0"><map name="MapWest_NowServing"><a href="javascript:void(0)" onmouseover="swapImage('images/map/MapWest_WA.png')" onmouseout="swapImage('images/map/MapWest_NowServing.png')"><area title="Washington" shape="rect" coords="73,9,160,70" href="#" alt=""></a></map>
Is anyone able to tell me what I'm doing wrong/missing?
Thank you very much in advance!
Last edited by vairvixen; Aug 29th, 2009 at 7:43 pm. Reason: Needed to add code tags... noob mistake.
•
•
•
•
<SCRIPT language="javascript" type="text/javascript"> function swapImage(image) { var Map = (document.getElementById) ? document.getElementById('MapWest') : (document.images) ? document.images['MapWest'] : (document.all) ? document.all['MapWest'] : null; if(Map) Map.src = image; } </SCRIPT>
<SCRIPT type="text/javascript">
function swapImage(image) {
var Map = document.getElementById('MapWest') ||document.images['MapWest']|| MapWest||null;
if(Map) Map.src = image;
alert(Map) //tell us what is the value of this alert please.
}
</SCRIPT>
...because "Language" attribute for the script tag has been deprecated, and using them both (language and type) may cause problems. In case it worked - it might force the browser to use JavaScript v.1.0 mode engine (although I'm sure JS1.0 should be able to interpret your code) but depending on a browser may happen to drop it completely.
Biggest mistake I see in your code is the A Href tag nestled inside the Area tag instead of combined into 1 tag.
I used your code, and made images for the files it called to. I had to find a State Map image to use, but here is a cross-browser, working, and Validating on w3c Demo: http://www.beeerlover.org/imap.html
I luv image maps, wish adobe hadn't killed off Image Ready.
I used your code, and made images for the files it called to. I had to find a State Map image to use, but here is a cross-browser, working, and Validating on w3c Demo: http://www.beeerlover.org/imap.html
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Title</title><script language="javascript" type="text/javascript"><!-- function swapImage(image) { var Map = (document.getElementById) ? document.getElementById('MapWest') : (document.images) ? document.images['MapWest'] : (document.all) ? document.all['MapWest'] : null; if(Map) Map.src = image; } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } --></script></head><body onload="MM_preloadImages('images/map/MapWest_OR.png','images/map/MapWest_WA.png')"> <img src="images/map/MapWest_NowServing.png" alt="Hover Each State for More info" title="Hover Each State for More info" name="MapWest" width="700" height="508" border="0" usemap="#MapWest_NowServing" id="MapWest" /> <map name="MapWest_NowServing" id="MapWest_NowServing"> <area shape="poly" coords="60,83,72,86,70,97,133,106,142,53,88,39,85,57,63,44" title="Washington" href="javascript:void(0)" onmouseover="swapImage('images/map/MapWest_WA.png')" onmouseout="swapImage('images/map/MapWest_NowServing.png');MM_swapImgRestore()" alt="Washington" /> <area shape="poly" coords="34,153,117,175,125,138,123,135,136,115,132,107,71,97,71,89,59,86,37,131" title="Oregon" href="javascript:void(0)" onmouseover="swapImage('images/map/MapWest_OR.png')" onmouseout="swapImage('images/map/MapWest_NowServing.png');MM_swapImgRestore()" alt="Oregon" /> </map></body></html>
I luv image maps, wish adobe hadn't killed off Image Ready.
www.beeerlover.org <- my hobby with 15K+ Pink Floyd Images
www.bestbridalprices.com <- my job with 15K+ Wedding Dresses
www.bestbridalprices.com <- my job with 15K+ Wedding Dresses
![]() |
Similar Threads
- Trackpad leaves working almost........? (Troubleshooting Dead Machines)
- AJAX CalendarExtender is not working with chrome (ASP.NET)
- Daniweb with Google Chrome (DaniWeb Community Feedback)
- IE/Firefox/Chrome not loading web pages (Viruses, Spyware and other Nasties)
- Save button not working in Firefox or Chrome (PHP)
- AJAX not working in FF but is in IE (JavaScript / DHTML / AJAX)
- Download Google's new web browser CHROME! (Web Browsers)
- Please give me reviews of my site (Website Reviews)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Maximize and Minimize Events in Browsers
- Next Thread: calculating form problem
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column cookies createrange() css cursor debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select session shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





