简体   繁体   中英

IE7/8 Javascript Errors

I'm getting a JavaScript error whenever you click the title link; in essence this line: document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\\/a><br>'); It's frustrating me in a major way since all other browsers except IE7/8 don't have any issues. Yet, a majority of our visitors are using IE7/8. The problem only occur in IE, little else, however when I debug it is a javascript error so far as I will tell.

Thanks..

Here's the info:

IE8 Debugging:

Line: 1 
Error: Function expected 

myclick(3) 
Function expected JScript - window script block, line 1 character 1 

IE9 Debugging (in IE8 Mode):

myclick(7)
SCRIPT5007: The value of the property 'myclick' is null or undefined, not a Function object script block (4), line 1 character 1

This is Line 1:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><meta http-equiv="X-UA-Compatible" content="IE=edge" >

This is the full script code; Google Maps:

<script type="text/javascript">
  var MapCenter = new google.maps.LatLng(41.52369114627216,-90.57780953284453)
  var i = -1;
  var Lat=new Array();
  var Long=new Array();
  var MarkerTitle=new Array();
  var Display=new Array();
  var myclick = new Array();
  var gmarkers = new Array();
</script>

<script type="text/javascript">
  var i = i + 1;
  Lat[i] = [[Lat]];
  Long[i] = [[Long]];
  MarkerTitle[i] = '[[Title]]';
  Display[i] = '<table><tr><td><div style="color: #a41d21;font-size: 13px; font-weight: bold;">[[Title]]</div></td></tr><tr><td>[[Address]]<br />[[City]], [[State]] [[Zip]]</td></tr><tr><td>[[Phone]]</td></tr><tr><td><a href="mailto:[[Email]]">[[Email]]</a></td></tr><tr><td><a href="[[WebURL]]" target="_blank">[[WebURL]]</a></td></tr></table>';
</script>

<div id="LeftArea" style="width: 220px; float: left; border-bottom: 1px solid #dedede; padding: 5px 0 5px 0;">
  <div style="color: #a41d21;font-size: 13px; font-weight: bold;">
    <script type="text/javascript">
      document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\/a><br>');
    </script>
  </div>
  <div>
    [[Address]]<br />
    [[City]], [[State]] [[Zip]]
  </div>
</div>

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  function initialize() {
    myclick = function myclick(i) {
      google.maps.event.trigger(gmarkers[i], "click");
    }

    var myOptions = {
      zoom: 12,
      center: MapCenter,
      zoomControl: true,
      zoomControlOptions: {
        position: google.maps.ControlPosition.TOP_RIGHT,
        style: google.maps.ZoomControlStyle.SMALL
      },
      mapTypeControl: true,
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
      },
      scaleControl: true,
      scaleControlOptions: {
        position: google.maps.ControlPosition.TOP_CENTER
      },
      mapTypeId: google.maps.MapTypeId.ROADMAP,
    };

    var map = new google.maps.Map(document.getElementById('map_canvas'),myOptions);

    for (var i = 0, length = 50; i < length; i++) {
      var latLng = new google.maps.LatLng(Lat[i],Long[i]); 
      var InfoWindow = new google.maps.InfoWindow();

      var marker = new google.maps.Marker({
        position: latLng,
        map: map,
        title: MarkerTitle[i],
        html: Display[i]
      });

      gmarkers[i] = marker;

      google.maps.event.addListener(marker, 'click', function () {
        InfoWindow.setContent(this.html);
        InfoWindow.open(map, this);
      });
    }

    google.maps.event.addListener(map, 'click', function() {
      InfoWindow.close();
    });
  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

I don't think you need to include the function name in this variable definition:

myclick = new function(i) {
      google.maps.event.trigger(gmarkers[i], "click");
}

Replace

<script type="text/javascript">
document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\/a><br>');
</script>

by the following

<script type="text/javascript">
document.write('#' <a href="#" onclick="javascript:myclick(' + (i) + ')">'> + '[[Title]]' + '<\/a><br>');
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM