2

私がやりたいのは、コード内のすべてのアラートをカスタムアラート(「アラートを使用しました」)に変更することです。

var hardCodedAlert = alert; //I know this won't work.But what to do ?
window.alert=function(){
if(this.count == undefined)
this.count=0;
this.count=this.count+1;
if(this.count == 1)
hardCodedAlert("You used alert");
};
4

1 に答える 1

1

はい、できます(例):

var oldalert = window.alert;
window.alert= function alert(t){
  alert.count = !alert.count ? 1 : alert.count + 1;
  oldalert(t+' - That\'s alert nr '+alert.count);
};

このjsfiddleを参照してください

于 2012-04-22T10:12:50.477 に答える