douhan1992 2016-10-28 07:44 采纳率: 100%
浏览 484
已采纳

window.location.href无效[关闭]

I'm using this script on javascript to change location and get some variable in the url but window.location.href didn't work i can't redirect to another page

during some search i found i need to put return false;

i put it but also i don't have any result

R: No error message appear

How to solve that ?

function getPosition() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successPosition);
  } else {
    document.getElementById("result").innerHTML = "Your browser does not support geo location api"
  }

  function successPosition(position) {
    var lat = position.coords.latitude;
    var long = position.coords.longitude;
    document.getElementById("result").innerHTML = "Latitude:" + lat + "<br/>Longitude:" + long
    window.location.href = "facee.php?lat=" + lat + "&long=" + long;
  }
  return false;
}
<form method="POST" action="" enctype="multipart/form-data" onsubmit="return getPosition();">
  <input type="file" name="image" accept="image/*" capture="camera" class="filestyle" data-buttonBefore="true" data-iconName="glyphicon glyphicon-camera" data-buttonText="Take apicture." />
  </div>
  <div class="col-md-12"></div>
  <div class="col-md-4">
    <input type="submit" name="Add" value="Add" class="btn btn-success">
</form>
  • 写回答

5条回答 默认 最新

  • dtxa49711 2016-10-28 08:36
    关注

    After reading your comments, I THINK you want this

    function successPosition(position) {
      var lat = position.coords.latitude,
        long = position.coords.longitude,
        form = document.getElementById("myForm");
      document.getElementById("result").innerHTML = "Submitting Latitude:" + lat + "<br/>Longitude:" + long;
      form.lat.value = lat;
      form.long.value = long;
      form.submit(); // HERE we submit
    };
    
    function getPosition() {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(successPosition);
      } else {
        document.getElementById("result").innerHTML = "Your browser does not support geo location api ";
      }
      return false; // always block submission
    }
    

    using

    <form id="myForm" method="POST" action="facee.php" 
    enctype="multipart/form-data" onsubmit="return getPosition();">
      <input type="hidden" name="lat" value="" />
      <input type="hidden" name="long" value="" />
      <input type="file" name="image" accept="image/*" capture="camera" class="filestyle" data-buttonBefore="true" data-iconName="glyphicon glyphicon-camera" data-buttonText="Take apicture." />
      </div>
      <div class="col-md-12"></div>
      <div class="col-md-4">
        <input type="submit" name="Add" value="Add" class="btn btn-success">
    </form>
    <span id="result"></span>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000