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

1 Answer 1

-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:

<script language='javascript' type='module'> 
1
  • Thank you!! It works for me. :) Commented Mar 6, 2020 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.