留言板

How do add portlet namespace into a external javascript

miii suuu,修改在14 年前。

How do add portlet namespace into a external javascript

New Member 帖子: 24 加入日期: 08-7-6 最近的帖子
I was able to use portlet name space in jsp. But now I don't want to write script code in jsp
I want to move all those script into a .JS file but I get problem about portlet name space

Please help to give some advide,

Thanks,
Mark McLauchlan,修改在14 年前。

RE: How do add portlet namespace into a external javascript

New Member 帖子: 3 加入日期: 10-1-23 最近的帖子
I'm having the same issue. This code works if the javascript is defined within the page in a <script> block, but not if it's in an external .js file:

void function wsrp_rewrite_MyJavascriptFunction() {
alert('hello');
}

The .js file that appears on the client still contains the "wsrp_rewrite", i.e. no rewriting has happened.

Thanks
Hon Hwang,修改在12 年前。

RE: How do add portlet namespace into a external javascript

New Member 帖子: 17 加入日期: 11-7-4 最近的帖子
I used a work around that might solve your problem.

Basically, defince a <script> tag in JSP, set a variable to hold the namespace's value. Then in main.js, I was able to reference this variable.

2 assumptions:
  • All Javascript of a portlet operate in single space. That is JavaScript in JSP can be seen by external Javascript.
  • JSP with <script> gets loaded before main.js. I have main.js in <footer-portlet-javascript> tag of liferay-portal.xml.