[转]动态改变图片的useMap属性导致IE假死或崩溃!
项目中需要动态生成一个统计图形,在统计图上用MAP标签生成图形的tooltip,由于图片是通过AJAX方式加载的,每次的图形都不同,则相应的MAP信息也就不同了,于是问题就出现了:
每次更改图片的MAP时(img.useMap = "#mymap"),在我本机都是没问题的,很流畅,但别人的部分机器上就会出现IE假死的情况,甚至崩溃,很是郁闷,今天到Google了一下,发现确实有这个问题,而且仅限于IE7,摘抄如下:
引用
UseMaps Crash IE When Changed
By Shawn Olson
Posted on 03.31.08
Dynamically changing an image's usemap property can cause Internet Explorer to crash completely. You can encounter this problem if you have an image that is using an image map and then switch the image's usemap (and/or useMap) property to use an alternative image map. The crash happens when the image map you are changing to does not have as many area nodes as the current image map.
The solution to this problem is to add area nodes into the image map you are changing to before you change the image's usemap property. You can do this by running equalizeUseMaps() which is a function included in the JavaScript referenced below.
function equalizeUseMaps(currentUseMap,nextUseMap)
This function will add blank AREA nodes to nextUseMap if currentUseMap has more area nodes than nextUseMap has.
To use this function, add the following line of code to your HTML head:
<script type="text/javascript" src="http://www.shawnolson.net/scripts/areamap.js"></script>
Please include credit when using this script and read this site's Terms & Conditions before using.
原文地址为:http://www.shawnolson.net/a/1395/usemaps-crash-ie-when-changed.html
当图片将要使用的MAP标签中的AREA节点数量小于当前所用MAP的AREA节点数量时,IE就完蛋了。
解决办法就是在改变useMap属性之前,判断两个MAP中的AREA节点数量是否相等,如果不相等,则动态创建AREA节点,使他们相等。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」