开发者

Separating Javascript functions

I am wondering how javascripts get included in a jsp - can we put any code which the jsp will recognize and not just javascript code only in the .js file?

I have some common javascript code which needs to get executed on different pages, so I decided to place it in its own separate .js file and include it on all jsps which call that function.

The js function now refers to a key from a properties file and some other non-javascript code:

function openPrivacyStmntWindow(){
var url = <h:outputText escape="false" value="\"#{urls.u开发者_C百科rl_privacyStatement}\";" />
newwindow=window.open(url,'Terms','height=600,width=800,left=300,top=100,scrollbars=1');
newwindow.focus();
return false;

}

This function worked just fine when it was included in the jsp itself. Now that I have separated it into its own file it doesnt, do I need to include the properties bundle in this file.

The value="\"#{urls.url_privacyStatement}\";" is referring to a bundle called "urls" which has a key called "url_privacyStatement"

Also in Line 1 var url = <h:outputText escape="false" value="\"#{urls.url_privacyStatement}\";" /> the <h:outputText escape="false" ... /> will it cause any issues?

Thanks.


You can't use custom tags in your js files. But you can extract this to a separate jsp page and include it in all the pages. You can also set the contentType for that jsp to be text/javascript.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜