Message Boards

Multiple including javascript libs poroblem

thumbnail
Vahid Kh, modified 4 Years ago.

Multiple including javascript libs poroblem

Junior Member Posts: 54 Join Date: 8/6/19 Recent Posts
Hey friends 
I use this method for including a javascript library into my portlet :

<script>
        Liferay.Loader.define._amd = Liferay.Loader.define.amd;
        Liferay.Loader.define.amd = false;
    </script>
&nbsp; &nbsp; <script type="text/javascript" src="<%=request.getContextPath()%>/js/highcharts.js"  ></script>
&nbsp; &nbsp; <script>
        Liferay.Loader.define.amd = Liferay.Loader.define._amd;
    </script>
&nbsp; &nbsp; 

It works correctly if only there is one instance in a page, But for more instance , other instances not return error
How can I prevent including multiple time?
thumbnail
Olaf Kock, modified 4 Years ago.

RE: Multiple including javascript libs poroblem

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
Vahid Kh:

I use this method for including a javascript library into my portlet :
...

It works correctly if only there is one instance in a page, But for more instance , other instances not return error
How can I prevent including multiple time?

You'll declare it in your portlet's header as one of these:
com.liferay.portlet.header-portlet-javascript

com.liferay.portlet.footer-portlet-javascript