java - What is the best way to use context-param in JavaScript -


in web.xml set context param "pathtoimages". in jsp files path images files use el, this:

<img src="${initparam.pathtoimages}"/image.jpg" /> 

but have problem javascript. in js files have code:

setinnerhtml("someplace", "<.img src='images/s.gif'>");

i know isn't beautiful code isn't mine :) cannot pathtoimages in same way jsp. best way this?

pass parameter js function: function createimage(path) {..} , invoke createimage('${initparam.pathtoimages}')

another, perhaps better option have js variable , initialize desired value. in js file:

var imagepath;  function init(config) {     imagepath = config.imagepath; } 

and in header:

init({imagepath: '${initparam.pathtoimages}'}); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -