巫马秀洁 发表于 2013-11-10 23:53:56

如何解决jquery ui 1.7.2 的dialog的ie泄露

本帖最后由 bigbang 于 2010-5-14 15:03 编辑
/ C5 H7 _: L' R. L3 E
- H$ g7 J5 G; $ s9 F# U6 X  jquery ui 1.7.2的dialog在ie每次打开对话框在ie都是使内存增长,得到ie浏览器的url切换了才会释放内存,如果把网站做成frame主体的,即进入到网站都是统一的url就是噩梦。) U. o% G! X" f+ q1 {$ I. k" f
+ g% O6 E, k& P4 Z: B
  先简单看下dialog的内存增长,打开development-bundledemosdialogmodal-form.html,点击”create new user”:
# g: a/ e; T5 B, U N& v$ O: b4 Y. y: p9 Z1 J, H
  刚打开时候时ie内存:( B7 D. K$ G* X
  下载 (11.16 KB)
2010-5-14 15:037 j2 q1 f! Z+ v9 F# D

8 N8 N9 |2 J+ i! a" b1 r; f  10重复点击”Create new user”——关闭:
+ ]0 ?2 a7 ~* @3 v k( O下载 (13.04 KB)
2010-5-14 15:03
3 Y6 K* G: c8 [0 z0 c 
/ ^) s) i! u! F- ^2 V$ ) S  修改ui.dialog.js:
[*]$.extend($.ui.dialog.overlay, {
[*] instances: [],
[*] oldInstances: [], //修改一:添加oldInstances
[*] maxZ: 0,
[*] events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
[*] function(event) { return event + '.dialog-overlay'; }).join(' '),
[*] create: function(dialog) {
[*] if (this.instances.length === 0) {
[*] // prevent use of anchors and inputs
[*] // we use a setTimeout in case the overlay is created from an
[*] // event that we're going to be cancelling (see #2804)
[*] setTimeout(function() {
[*] // handle $(el).dialog().dialog('close') (see #4065)
[*] if ($.ui.dialog.overlay.instances.length) {
[*] $(document).bind($.ui.dialog.overlay.events, function(event) {
[*] var dialogZ = $(event.target).parents('.ui-dialog').css('zIndex') || 0;
[*] return (dialogZ > $.ui.dialog.overlay.maxZ);
[*] });
[*] }
[*] }, 1);
[*] // allow closing by pressing the escape key
[*] $(document).bind('keydown.dialog-overlay', function(event) {
[*] (dialog.options.closeOnEscape && event.keyCode
[*] && event.keyCode == $.ui.keyCode.ESCAPE && dialog.close(event));
[*] });
[*] // handle window resize
[*] $(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
[*] }
[*] //修改二:替换var $el;
[*] //var $el = $('').appendTo(document.body)
[*] // .addClass('ui-widget-overlay').css({
[*] // width: this.width(),
[*] // height: this.height()
[*] // });
[*] var $el = (this.oldInstances.pop() || $('').addClass('ui-widget-overlay'))
[*] .appendTo(document.body)
[*] .css({
[*] width: this.width(),
[*] height: this.height()
[*] });
[*] (dialog.options.bgiframe && $.fn.bgiframe && $el.bgiframe());
[*] this.instances.push($el);
[*] return $el;
[*] },
[*] destroy: function($el) {
[*] //修改三:替换注释的代码:
[*] //this.instances.splice($.inArray(this.instances, $el), 1);
[*] this.oldInstances.push(this.instances.splice($.inArray($el, this.instances), 1));
[*] if (this.instances.length === 0) {
[*] $().unbind('.dialog-overlay');
[*] }
[*] $el.remove();
[*]
[*] // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
[*] var maxZ = 0;
[*] $.each(this.instances, function() {
[*] maxZ = Math.max(maxZ, this.css('z-index'));
[*] });
[*] this.maxZ = maxZ;
[*] },
[*] height: function() {
[*] // handle IE 6
[*] if ($.browser.msie && $.browser.version < 7) {
[*] var scrollHeight = Math.max(
[*] document.documentElement.scrollHeight,
[*] document.body.scrollHeight
[*] );
[*] var offsetHeight = Math.max(
[*] document.documentElement.offsetHeight,
[*] document.body.offsetHeight
[*] );
[*] if (scrollHeight < offsetHeight) {
[*] return $(window).height() + 'px';
[*] } else {
[*] return scrollHeight + 'px';
[*] }
[*] // handle "good" browsers
[*] } else {
[*] return $(document).height() + 'px';
[*] }
[*] },
[*] width: function() {
[*] // handle IE 6
[*] if ($.browser.msie && $.browser.version < 7) {
[*] var scrollWidth = Math.max(
[*] document.documentElement.scrollWidth,
[*] document.body.scrollWidth
[*] );
[*] var offsetWidth = Math.max(
[*] document.documentElement.offsetWidth,
[*] document.body.offsetWidth
[*] );
[*] if (scrollWidth < offsetWidth) {
[*] return $(window).width() + 'px';
[*] } else {
[*] return scrollWidth + 'px';
[*] }
[*] // handle "good" browsers
[*] } else {
[*] return $(document).width() + 'px';
[*] }
[*] },
[*] resize: function() {
[*] /* If the dialog is draggable and the user drags it past the
[*] * right edge of the window, the document becomes wider so we
[*] * need to stretch the overlay. If the user then drags the
[*] * dialog back to the left, the document will become narrower,
[*] * so we need to shrink the overlay to the appropriate size.
[*] * This is handled by shrinking the overlay before setting it
[*] * to the full document size.
[*] */
[*] var $overlays = $([]);
[*] $.each($.ui.dialog.overlay.instances, function() {
[*] $overlays = $overlays.add(this);
[*] });
[*] $overlays.css({
[*] width: 0,
[*] height: 0
[*] }).css({
[*] width: $.ui.dialog.overlay.width(),
[*] height: $.ui.dialog.overlay.height()
[*] });
[*] }
[*]});
复制代码修改后,重复点击后不会使内存增加很多,第一次点击的时候还是会使内存增加很多。
5 }( K8 Q& c$ j7 K( X, {
0 K4 V' j; t5 K- V/ I* } 跟踪代码,使内存增加就两个地方的appendTo(“body”):8 w2 }' [' T, X4 C, |3 B, K2 {
& z. u' k1 h- ~0 z$ i/ H
221行:(uiDialog.next().length && uiDialog.appendTo('body'));
. f; u" }$ q, S# Y5 [/ }/ n& b2 h# ~! n& p
566行:var $el = $('').appendTo(document.body)$ F2 i! M! s `- D+ R5 O' j
" o+ Z- k3 ]+ ?$ N6 x# r: z
  怎么解决这个问题还没什么好的方法,希望大家支持!

宗政优悦 发表于 2013-11-10 23:55:08

发发呆,回回帖,工作结束~

单于力 发表于 2013-11-11 01:34:19

为了三千积分!

况雪毓 发表于 2013-11-11 01:45:23

求沙发

云兰月 发表于 2013-11-11 04:07:55

very good

秋咸英 发表于 2013-11-11 04:07:55

不错 支持一个了

甘叶吉 发表于 2013-11-11 05:32:34

向楼主学习

要做淑女 发表于 2013-11-11 06:28:57

看起来不错

言艳芳 发表于 2013-11-11 10:45:28

支持楼主,用户楼主,楼主英明呀!!!

凌梅梅 发表于 2013-11-11 12:35:57

啊啊啊啊啊啊啊啊啊啊啊

乐正以晴 发表于 2013-11-11 14:28:57

前排支持下

亢昭懿 发表于 2024-8-8 20:31:29

求沙发

穆野雪 发表于 2024-9-26 17:09:16

好帖必须得顶起

雍旎旎 发表于 2025-1-3 15:06:05

回个帖子,下班咯~

雍旎旎 发表于 2025-3-13 14:08:41

very good

于一璇 发表于 2025-4-12 21:56:38

我只是路过,不发表意见

柏嘉言 发表于 2025-4-19 08:08:39

支持支持再支持

隗春娇 发表于 2025-5-22 17:25:04

顶起顶起顶起

戴柔静 发表于 2025-6-17 10:57:56

沙发???

元慕旋 发表于 2025-7-20 14:34:34

支持,赞一个
页: [1]
查看完整版本: 如何解决jquery ui 1.7.2 的dialog的ie泄露