简体   繁体   中英

Javascript not working in chrome with a .php extension

I have a php page that calls a header ?php include 'inc/head.php'; ?.

In this header is a javascript function that I posted below. Everything works great in Firefox and even in IE(which is a miracle in itself.) However, in Chrome it does not work. It does work on a .html page but in the php pages nothing shows. Thanks so much in advanced.

<script type="text/javascript">
    <!--
         var timeout = 500;
         var closetimer = 0;
         var ddmenuitem = 0;

         // open hidden layer
         function mopen(id) {
             // cancel close timer
             mcancelclosetime();

             // close old layer
             if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';

             // get new layer and show it
             ddmenuitem = document.getElementById(id);
             ddmenuitem.style.visibility = 'visible';

         }
         // close showed layer
         function mclose() {
             if (ddmenuitem) ddmenuitem.style.visibility = 'hidden';
         }

         // go close timer
         function mclosetime() {
             closetimer = window.setTimeout(mclose, timeout);
         }

         // cancel close timer
         function mcancelclosetime() {
             if (closetimer) {
                 window.clearTimeout(closetimer);
                 closetimer = null;
             }
         }

         // close layer when click-out
         document.onclick = mclose; 
    // -->
   </script> 

As posted in the comments; your script is running and trying to get a canvas element in the head of the document. The canvas element does not exist at this point. You can wrap your script in a $(document).ready(function(){your script here} or place it just above the closing tag of body: your script here</body>

Your script includes google maps api but doesn't have a div with id of map_canvas.

Added center: new google.maps.LatLng(-34.397, 150.644), to the map_options variable

A bunch of script is commented out because of <!-- uncommented that script.

After all that it still doesn't do much (not getting menu's in Firefox or Chrome or IE). Maybe it works in other browsers because they actually show you a cached version of the page. Try control + F5 to force reload it.

When you open the page and select view source, then save that in a html file. Add the following as the first child of header: <base href="http://www.seadelightoceanfund.org/"> when you open that in any browser you should get the errors I got.

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