Page 1 of 1

Using local storage for image url

Posted: Sat Nov 24, 2012 2:30 am
by Ron5262221

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


Using local storage for image url

Posted: Sat Nov 24, 2012 11:50 am
by Eric5020946

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


Using local storage for image url

Posted: Sat Nov 24, 2012 9:35 pm
by Ron5262221

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);


Using local storage for image url

Posted: Sun Nov 25, 2012 2:10 am
by maxkatz

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.


Using local storage for image url

Posted: Sun Nov 25, 2012 3:13 am
by Ron5262221

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????


Using local storage for image url

Posted: Sun Nov 25, 2012 4:57 pm
by maxkatz

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