I'm looking for a good approach to manipulate some JS code from within a module call. (Using Drupal 6.)
I have a set of JavaScript functions I need to add to a page. (Regular JavaScript, no jQuery.) Unfortunately they rely on some variables from the page they are shown on. So my current approach is to generate all the JavaScript from within PHP code which results in a whole lot of escaped strings like $output .= ' var url = "'. $url . '";' . "\n";
, which is not so nice after 20-30 lines of code.
So I would like to move all the JavaScript code into it's own .js
file, and find a way to inject my variables. So far, the only solution I could come up with is putting it in a temporary file, read that, modify and save it to the /files
directory. But is there another, more preferred way?