• 0

web storage works offline, but not online


Question

hello

i have a site where i use web storage ( http://en.wikipedia.org/wiki/Web_storage ) and it works offline but when i put it online, it doesnt work. vry very strange. a server cannot limit if i use web storage or not rite??? its works offline on all browsers when it is on my local server but when on online, it doesnt work.

wat could be rong????

Recommended Posts

  • 0

I use both local and session storage objects in my applications; are the domains different from offline and online? If you set a key value pair when browsing localhost, then you will not be able to access them when you are browsing www.yoursite.com (and vice-versa).

subdomains are also subject to this; web.yoursite.come can not access mail.yoursite.com objects.

  • 0

I use both local and session storage objects in my applications; are the domains different from offline and online? If you set a key value pair when browsing localhost, then you will not be able to access them when you are browsing www.yoursite.com (and vice-versa).

subdomains are also subject to this; web.yoursite.come can not access mail.yoursite.com objects.

no.

on local i use: example.ex/something and example.ex/somethingelse that works (on both)

online i use (for the same above): something.example.com and somethingelse.example.com that does not work (on either)

my feeling is that indeed that ****ing subdomain has sumthin to do with it. any workaround????

  • 0

You could move your localStorage code to the root domain (so example.com), then embed the code through an iframe on both subdomains, and send messages between the two documents as a way to do it.

do u have anywhere i can see examples or tutorials or more indepth information?

thank u

  • 0

http://www.nczonline...n-localstorage/

Edit: You'll want to ensure that no other sites can embed the code and issue commands to your code, it covers it in the article but it won't hurt to mention it again.

:laugh: this is the same exact page i looked up when i posted about maybe subdomains being a pain.....

i have several problems with that implementation......*sighs* im not sure this is going to be easy as the situation is kind of complicated.

my root domain is tecnically a subdomain....so thats going to be problematic.

if you have sum time to spare (and want to), The_Decryptor, a 1 on 1 pm session wud be nice and helpful.

tanks to all for the advice and comments

  • 0

Well, if you're in the situation where you don't control the root domain, only the subdomains, then you'd have to have one "master" subdomain, and have the second subdomain use that for storage (Using the same postMessage setup as you would use for subdomain > domain communication)

  • 0

Well, if you're in the situation where you don't control the root domain, only the subdomains, then you'd have to have one "master" subdomain, and have the second subdomain use that for storage (Using the same postMessage setup as you would use for subdomain > domain communication)

so it wud be the same implementation? ok will give it a go and see if sumthin explodes.

btw this also works on my local rite? ill implement in first in my local then pass it...

  • 0

got it to work (had some stuff to do)

i just have a very noob javascript question:


/*java script up here*/
var remoteStorage = new CrossDomainStorage("http://example.dev", "/server.html");
remoteStorage.requestValue("lookforme", function(key, value){
alert("The value for '" + key + "' is '" + value + "'");

});
alert ("alert 2 : I want to print/use value on the outside" + value);
/*javascript down here*/
[/CODE]

pretty selfexplains....i want to use value on the onside of that little variable/function (for example in that thing that says alert 2). how to do it????

  • 0

Should work, but not tested:

/*java script up here*/
var remoteStorage = new CrossDomainStorage("http://example.dev", "/server.html");
		 value = remoteStorage.requestValue("lookforme", function(key, value){
		 alert("The value for '" + key + "' is '" + value + "'");
		 return value;

		 });
alert ("alert 2 : I want to print/use value on the outside" + value);
/*javascript down here*/

  • 0

/*java script up here*/
var remoteStorageValue = "";
var remoteStorage = new CrossDomainStorage("http://example.dev", "/server.html");
                 remoteStorage.requestValue("lookforme", function(key, value){
                 alert("The value for '" + key + "' is '" + value + "'");
                 remoteStorageValue = value;
                 });
alert ("alert 2 : I want to print/use value on the outside" + remoteStorageValue);
/*javascript down here*/

You have to set the global value within the callback function, returning it won't work (Since you're assigning the return of "requestValue" to the variable, not the value of the callback which can happen at a later time)

  • 0

/*java script up here*/
var remoteStorageValue = "";
var remoteStorage = new CrossDomainStorage("http://example.dev", "/server.html");
				 remoteStorage.requestValue("lookforme", function(key, value){
				 alert("The value for '" + key + "' is '" + value + "'");
				 remoteStorageValue = value;
				 });
alert ("alert 2 : I want to print/use value on the outside" + remoteStorageValue);
/*javascript down here*/

You have to set the global value within the callback function, returning it won't work (Since you're assigning the return of "requestValue" to the variable, not the value of the callback which can happen at a later time)

i changed it to that code and it says that RemoteStorageValue ' s value is simply undefined

  • 0

It shouldn't say that since the first line sets it to "", which is different from undefined.

There is another issue of course, the second alert will fire before the callback could/will, so it won't see the value that the callback will.

  • 0

It shouldn't say that since the first line sets it to "", which is different from undefined.

There is another issue of course, the second alert will fire before the callback could/will, so it won't see the value that the callback will.

well it is undefined.....tried putting a word and same thing.

and that other issue you mentioned, may have to do with it:

there are 2 lines:

alert("The value for '" + key + "' is '" + value + "'");

alert ("alert 2 : I want to print/use value on the outside" + remoteStorageValue);

well alert 2 pops up before "the value for...." so I imagine it is because of what you mentioned. how do i fix it???

  • 0

The only way to fix it is to structure your code such that you don't try reading the value directly after issuing the cross domain call. Even if it execute instantly, JavaScript won't call your callback function until after the current function has finished executing.

If you separate your code into 2 different sections, one which asks for information and one that processes it, you could just make the first part issue the cross-domain call, and have the callback function invoke the second part of your code.

  • 0

The only way to fix it is to structure your code such that you don't try reading the value directly after issuing the cross domain call. Even if it execute instantly, JavaScript won't call your callback function until after the current function has finished executing.

If you separate your code into 2 different sections, one which asks for information and one that processes it, you could just make the first part issue the cross-domain call, and have the callback function invoke the second part of your code.

Well the only thing that comes to mind is sumkind of "sleep" function after running that cross domain call. tis will give it enough time to finish and will be able to get the valuer rite?

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.