1

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 <= $count; $i++) {
     $file_path = "/abcd.html";

     echo "counter:$i";
     echo "<script language='javascript' type='text/javascript'>";
     echo "myFunction('".$file_path."', 'index_".$i."');";
     echo "</script>";
     }
     return 1;
}
0

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:

<script language='javascript' type='module'> 
| improve this answer | |
  • Thank you!! It works for me. :) – roger123 Mar 6 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.