Ron5262221
Posts: 0
Joined: Sat Nov 24, 2012 2:18 am

Using local storage for image url

I can map text data from my backend to local storage in my app and reuse the data on another page quite easily. However it doesn't work if the data is an image url. I can map the image url data to display correctly using both the image component and HTML panel, but if I save the url to local storage and then try to use it on another page it doesn't show. I make sure to set the property correctly and have tried to have the image show from local storage using both the image component and HTML panel.

Please help, it's driving me crazy for what should be a simple operation

Eric5020946
Posts: 0
Joined: Tue Sep 18, 2012 4:31 pm

Using local storage for image url

use stringify function before saving to localstorage
local storage breaks also characters like & etc.
I think this is a bug

Ron5262221
Posts: 0
Joined: Sat Nov 24, 2012 2:18 am

Using local storage for image url

Thanks. I'm assuming that this would be a javascript function. I'm pretty new to this, so could you share with me how to write the stringify function. I think it looks something like this but I'm not sure :

var r = JSON.stringify(value);
localStorage('key', r);

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Using local storage for image url

The above looks right. In general, you want to save just the image URL in local storage, there is no need to save the actual HTML tag.

Ron5262221
Posts: 0
Joined: Sat Nov 24, 2012 2:18 am

Using local storage for image url

Do I paste the above script in the "add JavaScript" inside the Data Mapping, or do I add this on event "success" ?

Exactly where and how would I paste the script????

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Using local storage for image url

Most likely on a click, just before you navigate.

I'd only save the actual URL, you don't need to save the HTML tag:

code
var url = "....&quot
localStorage.setItem('url', url);
/code

then on any other page you can read the URL:

code
var url = localStorage.getItem('url');
/code

Return to “Issues”