Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using OpenLayer.Popup.FramedCloud from OpenLayer (JavaScript Mapping Library). in the popup constructor there is a parameter called contentHTML. I put there html button with onlick event:

contentHTML = "<button type='button' onclick='alert()'>Hello</button>";

from some reason the button doesn't respond to a click. Why? Is there a solution for this?

Maybe this is because the web page is uploaded in Winform WebBrowser? I noticed that when I upload the page with a regular browser (chrome) everything's working but not in Winform WebBrowser.

the complete popup object:

        var lonlat = new OpenLayers.LonLat(lon, lat);
        var size = new OpenLayers.Size(300,200)
        var htmlString = "<button type='button' onclick='alert()'>Hello</button>";
    popup = new OpenLayers.Popup.FramedCloud("popup", 
                                              lonlat, 
                                              size, 
                                              htmlString,                 
                                              anchor=null,   
                                              closeButtonX =false);         
        popup.id = callId;
        g_waze_map.map.addPopup(popup);

thanks a lot.

share|improve this question
Can you upload an example to JSFiddle.net? – Myles Gray Feb 6 '11 at 16:02

1 Answer

up vote 2 down vote accepted
+50

Well, I'm developing and using OpenLayers.Popup.FramedCloud and works fine (even with your contentHTML). Here is my code:

// i.e. x = 100, y = 300;

var popup = new OpenLayers.Popup.FramedCloud(
    "getfeature",
    map.getLonLatFromPixel(new OpenLayers.Pixel(x,y)),
    new OpenLayers.Size(300,200),
    "<button type='button' onclick='alert()'>Hello</button>",
    null,
    true
);
popup.autoSize = false;
map.addPopup(popup);

The popup automatically open and shows me the button. When I click on it, an alert is displayed with text 'undefined'.

share|improve this answer
sorry, not working – Day_Dreamer Feb 5 '11 at 15:40
Can you post how are you creating the popup? Edit your main post please. Thanks! – Fran Verona Feb 5 '11 at 15:42
@Day_Dreamer What about changing the last two parameters of your FramedCloud constructor and using 'null' and 'true' respectively? – Fran Verona Feb 5 '11 at 15:52
@Ftan Verona Same effect... – Day_Dreamer Feb 5 '11 at 16:28
Try to define a basic Popup using OpenLayers.Popup class; use your own 'contenthtml' to fill the new popup and display it. Just to know if the problem is because of FramedCloud class dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/…. Use the example I've provided in the previous link. – Fran Verona Feb 5 '11 at 16:31
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.