首页 > 解决方案 > Google 地图信息窗口 - 使用 JavaScript 更改我的位置 - Asp.NET

问题描述

我在保存会话后尝试将我的网页重定向到我的 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);

标签: asp.netgoogle-mapsbuttononclickinfowindow

解决方案


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

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

在 JS 中重定向也是一个不错的参考如何重定向到另一个网页?

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


推荐阅读