1

在我的项目中,我有一些 javascript 来实现我的工作,但是当我启动页面时它没有占用,但是在重新加载页面后它正在工作。

这是代码:

<?php 
require_once"session.php";
$slat =$_GET['slat'];
$slang =$_GET['slang'];
$elat =$_GET['elat'];
$elang =$_GET['elang'];
?>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <?php require_once"header.php";?>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>Near My Location Contacts</title>
    <script src="http://maps.google.com/maps/api/js?sensor=false"
            type="text/javascript"></script>
    <script type="text/javascript">
   /* function refreshPage() {
        alert('dfg');
    window.location.href,
    {
      allowSamePageTransition : true,
      transition              : 'none',
      showLoadMsg             : false,
      reloadPage              : true
    }
}
refreshPage();*/
    //<![CDATA[
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
//var haight = new google.maps.LatLng(37.7699298, -122.4469157);
//var oceanBeach = new google.maps.LatLng(37.7683909618184, -122.51089453697205);
var haight = new google.maps.LatLng(<?php echo $slat;?>,<?php echo $slang;?>);
var oceanBeach = new google.maps.LatLng(<?php echo $elat;?>,<?php echo $elang;?>);
function initialize() {
  directionsDisplay = new google.maps.DirectionsRenderer();
  var mapOptions = {
    zoom: 14,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: haight
  }
  map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  directionsDisplay.setMap(map);
  directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}

function calcRoute() {
  var request = {
    origin:haight,
    destination:oceanBeach,
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC
  };
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}

    //]]>
  </script>
  </head>
  <body style="margin:0px; padding:0px;" onload="initialize();calcRoute()"> 
  <div data-role=page id=nmContacts >
    <div data-role=header data-theme="e" >
        <a href="geoMapGrid.php" data-icon="back" ><font size="2px">Back</font></a>
        <h1 align="left"><font size="2px">Near My Contacts</font></h1>
    </div>
  <div data-role=content style="width:100%;height:100%;">
  <div data-role=content id="map_canvas" style="width:95%; height:300px"></div>
<div id="directionsPanel" style="width:97%;height 100%"></div>

</div>

  </body>
</html>

在上面我有body onload,它在刷新后第一次没有工作,只有它在工作。

4

1 回答 1

0

这是答案:

      Before You are calling to this page You have to specify in href like the following

假设您要加载以下链接:

<a href="sample.php" rel="external">sample</a>

这里 `href="external" 你必须指定否则它不会工作.....

于 2012-11-02T07:01:08.490 回答