スポンサードリンク

bodyタグでのonloadイベントを外部Scriptファイルに記述する方法

◆<body onload=”initialize()”>をbodyタグの代わりにscriptに記述したい・・・・。

あちこちのサイト覗いても良くわからないのでscriptへ下記を記述したらOKでした。scriptの最後に書いておけば良いのか?

まあ、動くのでメモ。

◆案1

<script type="text/javascript">
function initialize() 
{
 var myLatlng = new google.maps.LatLng(35.65858, 139.74538);
    var myOptions = 
    {
    zoom: 8,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new    
    google.maps.Map(document.getElementById("map_canvas"), myOptions);
}
window.onload = initialize;
</script>

◆案2

<script type="text/javascript">
    window.onload = function () {
        initialize();
    }
</script>


◆Google Maps JavaScript API V3

スポンサードリンク

Related Posts

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <img localsrc="" alt="">