How to call custom javascript function defined in js file from .module file I have some custom menu defined for which in the page callback function I want to execute some javascript function defined in some js file which is included in .info file.

The alert and console.log works as file is included on the page and loading successfully in browser, but custom js function not working. It says function is not defined.

.info file:

scripts[] = js/code_init.js


Here is my code in .module file:

function mymod_process_file(){

     $count = 2; 
     for($i = 1; $i &lt;= $count; $i++) {
     $file_path = "/abcd.html";

     echo "counter:$i";
     echo "&lt;script language='javascript' type='text/javascript'&gt;";
     echo "myFunction('".$file_path."', 'index_".$i."');";
     echo "&lt;/script&gt;";
     }
     return 1;
}
I have faced same kind of issue few days ago and I have resolved it by adding type as module to the script tag. All script with type=module have differ attribute. It download such js parallel with loading of other page and then run them in order but after the parsing is done.

This might help you:

&lt;script language='javascript' type='module'&gt;