This is a simple yet useful example to check if a function exists in JavaScript.
<input type="button" onclick="checkFunctionExist();" value="Check Function Existence" />
<script type="text/javascript" language="javascript">
 function testFunction() {
 }
 function checkFunctionExist() {
  if (window.testFunction) alert('testFunction exists');
  else alert('testFunction does not exist');
  if (window.nonExistantFunction) alert('nonExistantFunction exists');
  else alert('nonExistantFunction does not exist');
 }
</script>
To check whether a function exists on the parent page (the page which opened the dialog window), use:
if(window.opener.testFunction) alert('testFunction exists');
else alert('testFunction does not exist');






 

 
 
 
0 comments:
Post a Comment