2016-10-11 47 views
0

在我的索引我有<a href="/dashboard/gov.html">Government dashboard</a>哪些链接到我的gov页面,并在我的gov页面上我有谷歌地图API和我自己的JavaScript。但是当我点击链接到政府页面时,只有我自己的一个js可以正常工作。 奇怪的是,如果我只是重新加载gov.html(或设置为根)而不是点击重定向链接似乎工作正常。js无法正确加载轨道上的红宝石

下面是HTML一部分利己工作:

<div id='map' style='height:280px; width:400px' /> 

<script src="https://maps.googleapis.com/maps/api/js?key=XXX"></script> 

<script> 
     var map = new google.maps.Map(document.getElementById('map'), { 
        center: new google.maps.LatLng(31.267401, 121.522179), 
        mapTypeId: google.maps.MapTypeId.ROADMAP, 
        zoom: 11 
       }); 

           var t = new Date().getTime(); 
     var waqiMapOverlay = new google.maps.ImageMapType({ 
        getTileUrl: function(coord, zoom) { 
          return 'http://tiles.aqicn.org/tiles/usepa-aqi/' + zoom + "/" + coord.x + "/" + coord.y + ".png?token=_TOKEN_ID_"; 
        }, 
        name: "Air Quality", 
     }); 

     map.overlayMapTypes.insertAt(0,waqiMapOverlay); 
</script> 

    </th> 
    <th><img id="imgtraffic" width="395" height="280" /></th> 
    </tr> 
</table> 

<table align="center" width="811" border="1"> 
    <tr> 
    <td bgcolor="#9AD7F1" width="811">City Heat Map</td> 
    </tr> 
    <tr> 
    <td><div id="container"></div> 
    <div class="button-group"> 
     <input type="button" class="button" value="Show heat map" onclick="heatmap.show()"/> 
     <input type="button" class="button" value="Close heat map" onclick="heatmap.hide()"/> 
    </div> 
    <script> 
     var map = new AMap.Map("container", { 
     resizeEnable: true, 
     center: [116.418261, 39.921984], 
     zoom: 11 
    }); 
    if (!isSupportCanvas()) { 
     ... 
    </script> 

    </td> 
    </tr> 
</table> 

非常感谢你的帮助。

+0

在浏览器中启动控制台,并检查单击链接时是否出现错误。 –

回答

0

感谢所有,实际上只是简单地修改链接

<%= link_to 'Government dashboard', "/dashboard/gov.html", data: { turbolinks: 'false'} %> 

的属性来禁用turbolins是确定的。

3

尽量把你的代码中

$(document).on('turbolinks:load', function() { 
    Your code here 
}) 
+0

'turbolinks'更快的页面加载和我js存在的祸害。 – engineersmnky