2016-10-11 81 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