社内のWEBシステムについて、IE→Chromeの置き換え対応を実施しております。
その中で「ボタンの二重クリックを抑止する機能」について
IEの時にはローディング中に再度クリックすると以下の箇所で「loading」が格納されており
alertが出力されておりました。
Javascript
1return (document.readyState != null && document.readyState != "complete");
しかしChromeで実行いたしますと
ローディング中にクリックした場合でも「complete」が格納されてしまい
二重クリックが抑止できない状況( alert("処理中です…") が出力されない)となります。
Chromeで動作が想定通りとなるようにする方法についてご教授いただければ幸いです。
また、Javascript自体初学者となりますので情報に不足など御座いましたら
大変お手数ですが、ご質問いただけますと幸いです。
以上、よろしくお願いします。
Javascript
1// 画面ロード処理 2onload = function () { 3 return window_Load(); 4} 5 6function window_Load() { 7 var i; 8 9 for (i = 0; i < document.links.length; i++) { 10 var item = document.links[i] 11 Object.Aspect.around(item, "onclick", checkLoading); 12 } 13 14 var items = document.body.getElementsByTagName('input'); 15 16 for (i = 0; i < items.length; i++) { 17 var item = items[i]; 18 19 if (item.type == "button" || 20 item.type == "submit" || 21 item.type == "reset" || 22 item.type == "image" 23 ) { 24 Object.Aspect.around(item, "onclick", checkLoading); 25 } 26 } 27 28 for (i = 0; i < document.forms[0].elements.length; i++) { 29 var item = document.forms[0].elements[i]; 30 31 if (item.type == "text" || 32 item.type == "button" || 33 item.type == "submit" || 34 item.type == "reset" || 35 item.type == "checkbox" || 36 item.type == "radio" || 37 item.type == "select-one" || 38 item.type == "select-multiple" || 39 item.type == "textarea" || 40 item.type == "password" 41 ) { 42 try { 43 item.focus(); 44 break; 45 } catch (e) { 46 // 47 } 48 } 49 } 50 51 return true; 52} 53 54// 2度押し抑止アスペクト 55var checkLoading = function (invocation) { 56 if (isDocumentLoading()) { 57 alert("処理中です…"); 58 return false; 59 } 60 61 return invocation.proceed(); 62} 63 64// 画面描画が終わったかどうか 65function isDocumentLoading() { 66 return (document.readyState != null && document.readyState != "complete"); 67} 68 69// アスペクト用 70Object.Aspect = { 71 _around: function (target, methodName, aspect) { 72 var method = target[methodName]; 73 74 target[methodName] = function () { 75 var invocation = { 76 "target": this, 77 "method": method, 78 "methodName": methodName, 79 "arguments": arguments, 80 "proceed": function () { 81 if (!method) { 82 return true; 83 } 84 85 return method.apply(target, this.arguments); 86 } 87 }; 88 89 return aspect.apply(null, [invocation]); 90 }; 91 }, 92 around: function (target, methodName, aspect) { 93 this._around(target, methodName, aspect); 94 } 95}

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/10 04:14
2022/06/13 04:02