How to execute js function in body onload

Hi, fellows

I have a js function which I want to be execute in

Is it possible to do that?

Thanks in advance.

0 votes

1 answers

2494 views

ANSWER



Hi,

Easiest way to achieve that is to use jQuery:

  <script>
    jQuery(document).ready(function() {
      // javascript to execute on load
    });
  </script>
1 votes



And to include that easily I think the easiest way it to add this javascript fragment in a dedicate javascript file for instance name it myfunc.js

  • You create a regular Nuxeo project (not webEngine) with Nuxeo IDE.
  • Copy your myfunc.js file into src/main/resources/web/scripts/myfunc.js in your project.
  • Add this following contribution in src/main/resources/OSGI-INF/myproject-widget-contrib.xml

Here is the contribution:

 &lt;component name=&quot;fr.mycompany.myproject.widget.contrib&quot;&gt;
     &lt;!-- to be sure to be deployed AFTER the default configuration to override it--&gt;
     &lt;require&gt;org.nuxeo.theme.nuxeo.default&lt;/require&gt;

    &lt;!-- first you declare your javascript resources --&gt;
    &lt;extension target=&quot;org.nuxeo.theme.services.ThemeService&quot; point=&quot;resources&quot;&gt;
      &lt;resource name=&quot;myfunc.js&quot;&gt;
        &lt;path&gt;scripts/myfunc.js&lt;/path&gt;
      &lt;/resource&gt;
    &lt;/extension&gt;

    &lt;!-- and you override a xhtml fragment present everywhere in default Nuxeo JSF pages
            to append your javascript fragment --&gt;
    &lt;extension target=&quot;org.nuxeo.theme.services.ThemeService&quot; point=&quot;views&quot;&gt;
      &lt;view name=&quot;nuxeo5 includes&quot; template-engine=&quot;jsf-facelets&quot;&gt;
        &lt;resource&gt;myfunc.js&lt;/resource&gt;
      &lt;/view&gt;
    &lt;/extension&gt;

 &lt;/component&gt;
01/30/2012