スポンサードリンク

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

<body onload=”onLoad()”>等のイベントをwordpress(php)でGoogle Maps APIをやる場合にどうしたらいいかなと、v3をチラ見していたら、この方のv3の記述でふと・・・window.onload ・・・・ブラウザによっては問題があるようなこともどこかのサイトに書いてありましたがまあOKで。

Scriptファイル内にbodyタグのイベント記述する方法なのですが、次のようなもの。wordpressでは重宝。


サンプル
  • bodyタグでイベント指定
<body onload=”load();” onunload=”GUnload();”>
<script type=”text/javascript”>
// <![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map100 = new GMap2(document.getElementById(“map”));
map.setCenter(new GLatLng(35.71515, 139.39008), 17, G_SATELLITE_MAP);
var marker = new GMarker(map100.getCenter());
map.addOverlay(marker);
}
}
// ]]>
</script>

  • スクリプトで指定
<body>
<script type=”text/javascript”>
// <![CDATA[
window.onload=load;
function load() {
if (GBrowserIsCompatible()) {
var map100 = new GMap2(document.getElementById(“map”));
map.setCenter(new GLatLng(35.71515, 139.39008), 17, G_SATELLITE_MAP);
var marker = new GMarker(map100.getCenter());
map.addOverlay(marker);
}
}
window.onunload = GUnload;
// ]]>
</script>

スポンサードリンク

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="">