2012-04-11 60 views
1

http://jsfiddle.net/VtNaU/functionCallOnClose不JQuery的DOMWindow插件工作

「functionCallOnOpen」似乎很好地工作,但「functionCallOnClose」(一個我真的想使用)似乎並沒有工作。我也嘗試過.closeDOMWindow click(),但只有在關閉按鈕被點擊的情況下才會被調用,而不是在外部區域被點擊的情況下(這也會關閉窗口)。 這裏的插件的源代碼: http://swip.codylindley.com/jquery.DOMWindow.js

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
<script src="http://swip.codylindley.com/jquery.DOMWindow.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 
$('#test1').click(function(event) { 
    $.openDOMWindow({ 
     functionCallOnOpen: function() { 
      alert("opening"); 
     },  
     functionCallOnClose: function() { 
      alert("closing"); 
     }, 
     height:100, 
     width:200, 
     windowSourceID:'#theWindow' 
    }); 
}); 
}); 
</script> 
<button id="test1">Open Window</button> 

<div style="display:none;" id="theWindow"> 
<h1>Test</h1> 
<button class="closeDOMWindow">Close</button> 
</div> 

回答

1

這個腳本有一些問題,但你可以通過使用jQuery找到一個貼心的功能,以您的按鈕避免在腳本的路徑:

http://jsfiddle.net/cybermonk/Zd78c/

祝你好運!

+0

感謝它工作更好,但有一個新問題....如果你點擊關閉按鈕,它會反覆顯示「關閉」警報 - 每次一次你關上了窗戶。因此,如果窗口已關閉10次(通過單擊「關閉」或在窗口外單擊),單擊「關閉」後會出現11次「關閉」警報。編輯DOMWindow腳本:http://sky-walker.net/temp/test/jquery.DOMWindow-new.js – 2012-04-25 03:55:54

+0

嗨,對不起,我不知道你說什麼,當你說「試着回滾.... 「 也在那個jsfiddle它不檢測,如果窗口關閉,如果你點擊窗外... – 2012-04-26 04:50:48

+0

更新我的小提琴http://jsfiddle.net/cybermonk/Zd78c/,問題依然存在,但我的小提琴避免該路徑(每次關閉時都會在關閉函數上累積調用)。還打開控制檯,以便您可以看到日誌語句... – 2012-04-26 17:22:24