Reading a localStorage property in browser and use it in sightly-test condition | Adobe Higher Education
Skip to main content
Level 2
August 22, 2017
Respondido

Reading a localStorage property in browser and use it in sightly-test condition

  • August 22, 2017
  • 2 respostas
  • 3524 Visualizações

Hi,

I have a Path stored in the localStorage of my browser and would like to use it to test a path condition in Sightly.

Can you please let me know if this can be accomplished? If Yes, a prototype of the code would help.

Thanks in advance.

Regards,

Sagar

Este tópico foi fechado para respostas.
Melhor resposta por susheel

Hi Sagar,

Reading localstorage directly in sightly is not possible. Localstorage is a related to client side and passing that value to directly to sightly is not possible. You might have to write some servlet :

Make an ajax  call in the component like below:

var url = "/bin/someservlet?localstorageval=" + localStorage.getItem("somelocalstorage") + "&resourcepath="+${resource.path}

In the servlet you can set the value of the localstorage to the resource path, which we are passing to the servlet.

Now you can access the value as ${properties.whatevervalue}

whatevervalue = This is the value which you set to the resource(component resource).

This is not a good solution but this is what I got it in my mind.

You can add a hidden field to you dialog and set some default value to it.

This might not work on the first load because ajax call will be done after sightly it already loaded.

2 Respostas

kautuk_sahni
Community Manager
Community Manager
August 22, 2017
susheel
susheelResposta
Level 5
August 22, 2017

Hi Sagar,

Reading localstorage directly in sightly is not possible. Localstorage is a related to client side and passing that value to directly to sightly is not possible. You might have to write some servlet :

Make an ajax  call in the component like below:

var url = "/bin/someservlet?localstorageval=" + localStorage.getItem("somelocalstorage") + "&resourcepath="+${resource.path}

In the servlet you can set the value of the localstorage to the resource path, which we are passing to the servlet.

Now you can access the value as ${properties.whatevervalue}

whatevervalue = This is the value which you set to the resource(component resource).

This is not a good solution but this is what I got it in my mind.

You can add a hidden field to you dialog and set some default value to it.

This might not work on the first load because ajax call will be done after sightly it already loaded.