Javascript functions in javascript.php

21.9.1. Javascript functions in javascript.php

PHP-Nuke come with its own Javascript functions included in the file javascript.php, located under the includes folder. You can add your own Javascript code there, if you follow some simple rules:

  • Use a decent text editor (see Chapter 11) to edit the file.

  • Append your code after the code already there, but before the ending ?> line.

  • "echo" each line of your Javascript script. Example: Instead of entering directly the script code:

    <script type="text/javascript">
    function openwindow(){
  • enter it with "echo"s as:

    echo "<script type=\"text/javascript\">\n";
    echo "<!--\n";
    echo "function openwindow(){\n";
    echo "\"modules/$name/copyright.php\",\"Copyright\",
    echo "}\n";
    echo "//-->\n";
    echo "</script>\n\n";
  • Enclose each line in double quotes, like a string, and escape (with a backslash \) any double quote inside that string.

  • Add a newline character (\n) to the string, before the closing double quote[1].

  • End each line, like every PHP line, with a semicolon (;).

If you use vi (see Section 11.1), the following sequence of vi commands, applied to a Javascript file, will produce the right PHP code to append in the javascript.php file:

1,$s/"/\\"/g (1)
1,$s/^/echo "/ (2)
1,$s/$/";/ (3)
1,$s/";$/\\n";/ (4)
Escape all double quotes.
Add 'echo "' at the start of every line.
Add '";' at the end of every line.
Add a newline '\n' at the end of each Javascript line.

You can then include calls to your Javascript functions in the HTML code of your module. You echo the Javascript code, just like any other HTML code.



the "" line in the example above is actually a long line that has been broken to 3 lines only for layout purposes, that's why there are no newlines (\n) at the ends of two lines (just as there is no semicolon for the same reason).


Site Info v2.2.2

Last SeenLast Seen
Server TrafficServer Traffic
  • Total: 373,251,141
  • Today: 59,317
Server InfoServer Info
  • Dec 13, 2018
  • 03:20 pm CET