OpenLayers: Popup message on map click

I’d like to popup a message when a user clicks anywhere on the map. Unfortunately any sample code I found depends on either a marker or a polygon etc. Does anybody have code which just shows how to use the popup control with a simple single click? So far I’ve successful used sample “click.html” yet instead of a alert I’d like to popup a message box.


Have a look at (JS without “minimized” Filename). It shows you how to add a so called ‘feature’ that is a represantation on the vector layer. I guess this is what you want?

Not quite. Your sample depends on certain features outlined on the map, you can only click a feature. Mine allows to click anywhere on the map ( yet then I have no feature I can link the popup with. I tried

  trigger: function(evt) {
    var lonlat = map.getLonLatFromViewPortPx (evt.xy).transform (projMercator, projLonLat);
    alert ("You clicked near " + + " N, " + lonlat.lon + " E");
    feature = evt.feature;
    popup = new OpenLayers.Popup.FramedCloud ("info", lonlat, null,
              "<h2>"+ "Test" + "</h2>", null, true, onPopupClose);
    feature.popup = popup;
    popup.feature = feature;
    map.addPopup (popup);

I guess the “feature = evt.feature;” is wrong but I don’t know how to fix it.