当前位置: 动力学知识库 > 问答 > 编程问答 >

How to include JavaScript file in Liferay Portlet?

问题描述:

I am not able to include http://maps.googleapis.com/maps/api/js?sensor=false. Whenever I load my portlet for the first time it doesn't work but if I refresh the same page then it starts working fine. I don't know what the issue is. Please Help.

网友答案:

One of the clean ways to include js file in a portlet, independent of the portal server is to configure in portlet deployment descriptor file as below. For liferay, it would be liferay-portlet.xml.

<portlet>
    <portlet-name>MySamplePortlet</portlet-name>
    <header-portlet-javascript>http://maps.googleapis.com/maps/api/js?sensor=false</header-portlet-javascript>
</portlet>
网友答案:

What do you mean by "it doesn't work"? Where did you put it. Inside portlet's jsp? Could you share code so we can see what you are doing.

Nevertheless this should work

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

<script>
    google.maps.event.addDomListener(window, 'load', initialize);

    var map;

    function initialize() {
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }
</script>

...

<div id="map_canvas" style="width:100%; height:100%"></div>
分享给朋友:
您可能感兴趣的文章:
随机阅读: