【问题标题】:Google Maps Info Window - Change my Location with JavaScript - Asp.NETGoogle 地图信息窗口 - 使用 JavaScript 更改我的位置 - Asp.NET
【发布时间】:2018-11-24 05:23:00
【问题描述】:

我在保存会话后尝试将我的网页重定向到我的 asp.net 项目的另一个路径,代码在此处:

(function (marker, data) {
    google.maps.event.addListener(marker, "click", function (e) {
        infoWindow.setContent('<div class="card" style ="width:200px;height:auto;">' +
        '<img class="card-img-top" src='+data.photo+' style="width:200px;height:auto;" >' +
        '<div class="card-body">'+
        '<h5 class="card-title">' + data.title + '</h5>' +
        '<p class="card-text">' + data.description + '</p>' +
        '<button id="btn_seedetails" >Click me</button>' +
        '</div>' + 
        '</div >' );
        infoWindow.open(map, marker);
        google.maps.event.addDomListener(document.getElementById('btn_seedetails'), 'click', sendit);                                           
   });

   function sendit() {
       '<%Session["ID_EVENT"] = "' + data.id + '"; %>';
       document.location.href = "AllConflicts.aspx";
       location.replace("AllConflicts.aspx")
   }
})(marker, data);

【问题讨论】:

  • 浏览器控制台说什么?
  • 说:未捕获
  • 您要添加多少个标记?因为它们都有一个具有相同 ID 的按钮。您还可以在 html 中使用 data-id="342" 并在 sendit/clicked 函数中访问该 id
  • 我添加了许多标记,因为数据库有

标签: asp.net google-maps button onclick infowindow


【解决方案1】:

也许使用查询字符串来传递数据:

function sendit() {
    window.location.href("AllConflicts.aspx?id=" + data.id);
}

在 JS How do I redirect to another webpage? 中重定向也是一个不错的参考

也许 data.id 在函数中不可用。您可能希望为 sendit 函数使用输入参数。

【讨论】:

  • 仍然无法正常工作,我认为这是因为 localhost 链接
  • 你能提供一个 jsfiddle 什么的吗?
  • 我已经解决了,我使用 c# 来响应重定向,并且在哪个侦听器中我等于我的 data.id 到一个隐藏字段
  • 所以问题的标题不再准确了? ;-) “使用 JavaScript 更改我的位置”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-11
  • 2015-09-12
  • 2018-10-15
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 2014-10-02
相关资源
最近更新 更多