How do I access javascript variables from script tag to jelly tags?

rock2freedom
Mega Contributor

Hi all,

I want to access a screen.height into jelly tag.

I am using the following code

<script>

var h11 = screen.height-280;

</script>

<j:set var="jvar_h1" value="${h11}"/>

<g:evaluate var="jvar_esh1" object="true" jelly="true">

var height123 = jelly.jvar_h1;   //This is not working

                               

</g:evaluate>

Can you please suggest me what is wrong I am doing here.

Thanks,

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Hi Soumen,



Due to the architecture of Jelly, I don't think this is going to work for you. The code in the script tag is run on the client after the Jelly processing has already happened (on the server.)



The XML tags (Jelly) get turned in to HTML, JavaScript, and CSS then sent to the browser. Then your h11 variable is set with the screen.height-280 value. There is no further Jelly processing at that time, so you cannot set a Jelly variable from a client script due to the order in which they are executed.


View solution in original post

3 REPLIES 3

Chuck Tomasi
Tera Patron

Hi Soumen,



Due to the architecture of Jelly, I don't think this is going to work for you. The code in the script tag is run on the client after the Jelly processing has already happened (on the server.)



The XML tags (Jelly) get turned in to HTML, JavaScript, and CSS then sent to the browser. Then your h11 variable is set with the screen.height-280 value. There is no further Jelly processing at that time, so you cannot set a Jelly variable from a client script due to the order in which they are executed.


rock2freedom
Mega Contributor

Hi Chuck Tomasi



I understand this,I think for this reason we can access the a value of a variable from jelly tag to script tag and the reversible process is not possible.



Thanks for your quick reply.


Yes, you are correct.



You can use a jelly variable to create dynamic client scripts because that processing is done on the server before the client (browser) gets the content. The reverse is not true because all the Jelly processing is done by the time the client script is on the browser and running.