title: dynamically call function javascript
body: <p>What I want to do is to separate all my JavaScript from the page, so it works for all with disabled JavaScript, but also be able to compile it using closure compiler's advanced compiling (http://closure-compiler.appspot.com/home).</p>
  
  <p>Here is how I started:</p>
  
  <p>From...</p>
  
  <pre><code>&lt;a href="javascript:doMultiple('download', 'release');"&gt;Create archive&lt;/a&gt;
  </code></pre>
  
  <p>to...</p>
  
  <pre><code>&lt;a class="javascript doMultiple download release" href="ca.php"&gt;CreateArchive&lt;/a&gt;
  </code></pre>
  
  <p>Then I loop all objects to find what have the class javascript first, etc: (links is an array of the a tags)</p>
  
  <pre><code>for (i = 0; i &lt; links.length; i = i + 1) {
      if (links[i].className.substr(0, 10) === "javascript") {
          jsArray = links[i].className.split(" ");
          links[i].style.display = "inline";
          if (links[i].addEventListener) {
              links[i].addEventListener("click", window[jsArray[1]], false);
          } else {
              links[i].onclick = window[jsArray[1]];
          }
          links[i].href = "#";
      }
  }
  </code></pre>
  
  <p>With this method javascript compressors will remove the function doMultiple because it's unused because it dosnt know I have a class with that...</p>
  
  <p>And my question is, how can I solve this, and if I can't, can I somehow get rid of the window[jsArray[1]] and do solve that in another way? Because I think that is not the best way to do it.</p>
  
  <p>A class can also be:</p>
  
  <pre><code>&lt;a class="javascript popUp register.php 350 300" href="register.php"&gt;Register&lt;/a&gt;
  </code></pre>
  
  <p>So I want to use this method for adding all JavaScript dynamically.</p>
  
  <p>Best regards,<br>
  Johan Svensson</p>