Reading a localStorage property in browser and use it in sightly-test condition | Community
Skip to main content
Level 2
Aug 22, 2017 10:22 AM UTC
Solved

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

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
susheel
susheelAccepted solution
Level 5
Aug 22, 2017 12:00 PM UTC

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 replies

susheel
susheelAccepted solution
Level 5
Aug 22, 2017 12:00 PM UTC

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.

Translate
kautuk_sahni
Employee
Aug 22, 2017 11:11 AM UTC
Kautuk Sahni