ASP.NET & JavaScriptã§ã³ã¼ãæ±æãããªãã§2度æ¼ãé²æ¢
以åãattachEventã§ã¯è¤æ°ã¤ãã³ããç»é²ãã¦åã®ã¤ãã³ãã®æ»ãå¤ãè¦ãã¨ããã®ãã§ããªãã¦æ¶çµ¶ãã¦ããããçµå±ãããããã¨ã¯ã¤ãã³ãï¼ã¡ã½ããï¼ã«å¯¾ãã¦ã¢ã¹ãã¯ããé©ç¨ããã°ããã¨ãããã¨ã«æ°ãã¤ãããããã調ã¹ãçµæããã°ããããµã¤ããããã¤ãè¦ã¤ããæ©éã³ããã®é¨ãããã§ç®çã®ãã®ãå®æ
ä¸ã®ã¹ã¯ãªãããå¥ãã¡ã¤ã«ã«ã§ããã¦ã対象ã®HTMLã«ã¦ã¤ã³ã¯ã«ã¼ãããã°ãå
¨ãªã³ã¯ã¨ãã¿ã³ã«ã¦2度æ¼ãé²æ¢æ©è½ãæè¼ã§ãã
ãã²ããããã¢ã¹ãã¯ããããã
// window ã® Load ã¤ãã³ããåå¾ããã window.onload = window_Load; function window_Load() { var i; // å ¨ãªã³ã¯ã®ã¯ãªãã¯ã¤ãã³ãã submittableObject_Click ã§åå¾ããã for (i = 0; i < document.links.length; i ++) { var item = document.links[i] Object.Aspect.around(item, "onclick", checkLoading); } // å ¨ãã¿ã³ã®ã¯ãªãã¯ã¤ãã³ãã submittableObject_Click ã§åå¾ããã for (i = 0; i < document.forms[0].elements.length; i ++) { var item = document.forms[0].elements[i] if (item.type == "button" || item.type == "submit" || item.type == "reset") { Object.Aspect.around(item, "onclick", checkLoading); } } return true; } //2度æ¼ãææ¢ã¢ã¹ãã¯ã var checkLoading = function(invocation) { if (isDocumentLoading()) { alert("å¦çä¸ã§ãâ¦"); return false; } return invocation.proceed(); } //ç»é¢æç»ãçµãã£ããã©ãã function isDocumentLoading() { return (document.readyState != null && document.readyState != "complete"); } //ã¢ã¹ãã¯ãç¨ Object.Aspect = { _around: function(target, methodName, aspect) { var method = target[methodName]; target[methodName] = function() { var invocation = { "target" : this, "method" : method, "methodName" : methodName, "arguments" : arguments, "proceed" : function() { if (!method) { return true; } return method.apply(target, this.arguments); } }; return aspect.apply(null, [invocation]); }; }, around: function(target, methodName, aspect) { this._around(target, methodName, aspect); } }
ãã¯ãªå
ã»ã»ã»ãã¨ããåèãµã¤ã
å®è£
http://d.hatena.ne.jp/akm/20060917#1158449489
ã³ãã¼å
http://d.hatena.ne.jp/masanobuimai/
ã¢ã¹ãã¯ãï½²ï¾ï¾ï½°ï½²
http://d.hatena.ne.jp/brazil/20061007/1160157179
ãã¾ã
http://codezine.jp/a/article/aid/769.aspx
Javascriptã®ãªãã¡ã¬ã³ã¹ã¯ãããããã便å©
第1çã®é ãã使ã£ã¦ã¾ãã