开发者

weird javascript image map behaviour with update panels in Chrome

开发者 https://www.devze.com 2022-12-14 11:40 出处:网络
I have discovered an odd bug in one of my apps when using Chrome. The app displays images with image maps which trigger javascript events. The images/maps are in update panels. When the update panel r

I have discovered an odd bug in one of my apps when using Chrome. The app displays images with image maps which trigger javascript events. The images/maps are in update panels. When the update panel refreshes, the image changes, and if you inspect the element the image map appears to have changed, but Chrome is still calling the old javascript function.

I have attempted to put together a simple example to demonstrate. It's a pretty poor example since it doesn't appear to do anything at all in any other browser, but I think it demonstrates the problem ok in Chrome (hopefully).

<form id="form1" runat="server">
    <asp:ScriptManager ID="MyScriptManager" runat="server"></asp:ScriptManager>
    <div>
        <a href="#" onclick="__doPostBack('MyUpdatePanel', '');">reload</a>
        <asp:UpdatePanel ID="MyUpdatePanel" runat="server">
            <ContentTemplate>
                <%=CreateClickable()%>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</form>


public string CreateClickable()
{
    if (IsPostBack)
        ret开发者_JAVA百科urn CreateClickable("red", "postback msg");
    else
        return CreateClickable("blue", "original msg");
}


private string CreateClickable(string color, string msg)
{
    string html;

    html = @"<map id=""myMap"" name=""myMap"">
                 <area shape=""rect"" coords=""0,0,100,100"" onclick=""alert('" + msg + @"');"">
             </map>";
    html += @"<img id=""myImg"" usemap=""myMap"" style=""height:100px; width:100px; background-color:" + color + @";"">";

    return html;
}


usemap=""#myMap"" try that

0

精彩评论

暂无评论...
验证码 换一张
取 消