Obtain the name of the Javscript execution function. The specific function is as follows:
The function name is getFuncName. You can directly use the getFuncName function to obtain the Javascript function name.
<Script language = "javascript">
Function getFuncName (_ callee ){
Var _ text = _ callee. toString ();
Var _ scriptArr = document. scripts;
For (var I = 0; I <_ scriptArr. length; I ++ ){
Var _ start = _ scriptArr [I]. text. indexOf (_ text );
If (_ start! =-1 ){
If (/^ functions * (. *). * rn/. test (_ text )){
Var _ tempArr = _ scriptArr [I]. text. substr (0, _ start). split ('rn ');
Return _ tempArr [_ tempArr. length-1]. replace (/(var) | (s *)/g ,''). replace (/=/g ,'');
} Else {
Return _ text. match (/^ functions * ([^ (] +). * rn/) [1];
}
}
}
}
Function (){
Return getFuncName (arguments. callee );
}
Var B = function (){
Return getFuncName (arguments. callee );
}
Window. alert (());
Window. alert (B ());
</Script>
Method for obtaining the name of the Javscript execution function