How to make Leaflet markers go to unique link? Currently marker.on near the bottom gets the same link for each marker. I would like it to assign the corresponding link from var data for each. Cannot change the formatting too much as it links to other javascript pages as well
//sample data values for populate map
var data = [
{"loc":[43.0680798,-89.4083302], "title":"Jordan's Big Ten Pub", "link":"Jordans_Big_Ten_Pub.html", "nid":"0"},
{"loc":[43.0678893,-89.4064022], "title":"The Red Zone Madison", "link":"The_Red_Zone_Madison.html", "nid":"1"},
{"loc":[43.0747636,-89.38156], "title":"Tipsy Cow", "link":"Tipsy_Cow.html", "nid":"52"}
];
var map = new L.Map('map', {zoom: 14, center: new L.latLng(43.072, -89.39) }); //set center from first location
map.addLayer(new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')); //base layer
var markersLayer = new L.LayerGroup(); //layer contain searched elements
map.addLayer(markersLayer);
var controlSearch = new L.Control.Search({
position:'topright',
layer: markersLayer,
initial: false,
zoom: 19,
marker: false
});
map.addControl( controlSearch );
////////////populate map with markers from sample data
for(i in data) {
var title = data[i].title, //value searched
loc = data[i].loc,
j=data[i].nid, //position found
marker = new L.Marker(new L.latLng(loc), {title: title}, {win_url: data[i].link } );//se property searched
marker.bindPopup('title: '+ title );
**marker.on('click', function(){window.location=(data[j].link)});**
markersLayer.addLayer(marker);
}