<div dir="ltr">I want to call a javascript function when a feature's popup is clicked. Tried hardcoding it because I couldn't make much out of the API documentation on events, but the map was capturing the clicks and I couldn't get around it (it worked but only after a second click_. So now I'm trying to do it via events.register.<div>
<br></div><div>Here is what I have:</div><div><br></div><div><div>var vector = new OpenLayers.Layer.Vector("Points",{</div><div><span class="" style="white-space:pre"> </span> eventListeners:{</div><div><span class="" style="white-space:pre"> </span> 'featureselected':function(evt){</div>
<div><span class="" style="white-space:pre"> </span> var feature = evt.feature;</div><div><span class="" style="white-space:pre"> </span> popup = new OpenLayers.Popup.Anchored("popup",</div>
<div><span class="" style="white-space:pre"> </span> OpenLayers.LonLat.fromString(feature.geometry.toShortString()),</div><div><span class="" style="white-space:pre"> </span> new OpenLayers.Size(275,71),</div>
<div><span class="" style="white-space:pre"> </span> '<div id="pincontent" onclick=""><h3>' + feature.attributes.title +'</h3><div style="display: none;" id="pindescription">'+ feature.attributes.content +'</div></div>',</div>
<div><span class="" style="white-space:pre"> </span> null,</div><div><span class="" style="white-space:pre"> </span> false</div><div><span class="" style="white-space:pre"> </span> );</div>
<div><span class="" style="white-space:pre"> </span> popup.imageSrc = 'img/popup.png';</div><div><span class="" style="white-space:pre"> </span> popup.autoSize = false;</div><div><span class="" style="white-space:pre"> </span> popup.backgroundColor = 'transparent';</div>
<div><span class="" style="white-space:pre"> </span> var offset = {'size':new OpenLayers.Size(0,0),'offset':new OpenLayers.Pixel(-74,-10)};</div><div><span class="" style="white-space:pre"> </span> popup.anchor = offset;</div>
<div><span class="" style="white-space:pre"> </span> popup.panMapIfOutOfView = true;</div><div><span class="" style="white-space:pre"> </span> popup.imageSize = new OpenLayers.Size(275,71);</div><div>
<span class="" style="white-space:pre"> </span> popup.relativePosition = "br";</div><div><span class="" style="white-space:pre"> </span> popup.calculateRelativePosition = function () {</div>
<div><span class="" style="white-space:pre"> </span> return 'tr';</div><div><span class="" style="white-space:pre"> </span> };</div><div><span class="" style="white-space:pre"> </span> feature.popup = popup;</div>
<div><span class="" style="white-space:pre"> </span> map.addPopup(popup);</div><div><span class="" style="white-space:pre"> </span> var popcontent = document.getElementById('pincontent');</div>
<div><span class="" style="white-space:pre"> </span> map.events.register('mousedown', popcontent, function(evt){alert('help')}, false);</div><div><span class="" style="white-space:pre"> </span> },</div>
<div><span class="" style="white-space:pre"> </span> 'featureunselected':function(evt){</div><div><span class="" style="white-space:pre"> </span> var feature = evt.feature;</div><div><span class="" style="white-space:pre"> </span> map.removePopup(feature.popup);</div>
<div><span class="" style="white-space:pre"> </span> feature.popup.destroy();</div><div><span class="" style="white-space:pre"> </span> feature.popup = null;</div><div><span class="" style="white-space:pre"> </span> }</div>
<div><br></div><div><span class="" style="white-space:pre"> </span> }</div><div><span class="" style="white-space:pre"> </span>});</div><div><span class="" style="white-space:pre"> </span>vector.addFeatures(features);</div>
<div><br></div><div><br></div><div><span class="" style="white-space:pre"> </span>// create the select feature control</div><div><span class="" style="white-space:pre"> </span>var selector = new OpenLayers.Control.SelectFeature(vector,{</div>
<div><span class="" style="white-space:pre"> </span> click:true,</div><div><span class="" style="white-space:pre"> </span> autoActivate:true</div><div><span class="" style="white-space:pre"> </span>}); </div><div><span class="" style="white-space:pre"> </span></div>
<div><span class="" style="white-space:pre"> </span>map.addLayers([osm, vector]);</div><div><br></div><div style>event.register in a few different places with no luck.. I feel like inside featureselected makes sense because elsewhere the popup will not actually exist. Any advice on getting this to work would be amazing</div>
<div></div>
</div></div>