If you implement a solution, while only one popup is active at a time (that is, every time a popup is not selected, it disappears), you will never have more than one popup at a time.
read this STACKOVERFLOW answer I wrote for this problem. you have all the necessary pseudo codes (with long explanations about everything).
if you don't need an explanation, this shows a solution:
var urlKML = 'parseKMLTrack07d.php'; var layerKML = new OpenLayers.Layer.Vector("KML1", { strategies: [new OpenLayers.Strategy.Fixed()], protocol: new OpenLayers.Protocol.HTTP({ url: urlKML, format: new OpenLayers.Format.KML({ extractStyles: true, extractAttributes: true, maxDepth: 2 }) }) }); var layerOSM = new OpenLayers.Layer.OSM(); var map = new OpenLayers.Map({ div: "map", layers: [ layerOSM, layerKML ] }); var selectStop = new OpenLayers.Control.SelectFeature(layerKML,{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect}); layerKML.events.on({ "featureselected": onFeatureSelect, "featureunselected": onFeatureUnselect }); map.addControl(selectStop); selectStop.activate(); function onFeatureSelect(event) { var feature = event.feature; var content = feature.attributes.name + '<br/>'+feature.attributes.description; popup = new OpenLayers.Popup.FramedCloud("chicken", feature.geometry.getBounds().getCenterLonLat(), new OpenLayers.Size(100,100), content, null, true, onFeatureUnselect); feature.popup = popup; map.addPopup(popup);
now if you REALLY want to destroy all pop-ups no matter what I am very discouraged:
function popupClear() {
source share