• 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.
  • Posts

    • New PowerToys update fixes memory leaks and other issues by Taras Buria Another bug-fixing update is available for PowerToys version 0.100. After releasing version 0.100.1 with a bunch of bug fixes and patches, Microsoft pushed version 0.100.2 to address two important issues with one of Command Palette Dock's features. With PowerToys 0.100.2, Microsoft fixed the performance meter displaying incorrect values and memory leaks, which are particularly unwanted things in the current situation with overpriced PC hardware. Here is the changelog: Reverted a Performance Monitor dock refresh change that forced item refreshes on every metric update Fixed a memory leak in the Performance Monitor dock extension by reusing stable network upload/download band items instead of creating new list items on each refresh For those unfamiliar, Command Palette Dock is a relatively new addition to PowerToys. It is a taskbar-like tool that you can keep on top of the screen to pin various useful widgets, commands, and more. It can display time, weather, your PC's performance metrics, and more. Microsoft introduced the Command Palette Dock in March 2026 in PowerToys 0.98. Microsoft has dedicated documentation for Command Palette Dock, and you can check it out on the official Microsoft Learn website. You can update PowerToys to the latest version by going to Settings > General and clicking "Check for updates." Alternatively, you can download the installer from GitHub using this link. In other news, Microsoft is working on a new window-management utility for PowerToys. Called Alt Window Cycle, it will let you use the Alt + ` shortcut to switch between different windows in a single app. You can learn more about the tool here.
    • You did take leaf out of Trumps book already and had brexit - only to harm yourself. The same goes with this AI nonsense. The obvious solution for these companies is to move their head office to Brussels. I can see quite much irony there... 🙂
    • Thank gawd AT&T never worked with the US gov....
    • Wonder if they are trying to slow down Linux traction (not saying this is the only factor) in the consumer space. With the most pressure probably being steam deck/box, etc.
  • Recent Achievements

    • First Post
      OffsetAbs earned a badge
      First Post
    • Reacting Well
      OffsetAbs earned a badge
      Reacting Well
    • First Post
      Kolakid60 earned a badge
      First Post
    • One Month Later
      xvvxcvv earned a badge
      One Month Later
    • Week One Done
      xvvxcvv earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      421
    2. 2
      +Edouard
      180
    3. 3
      PsYcHoKiLLa
      133
    4. 4
      neufuse
      71
    5. 5
      Steven P.
      70
  • Tell a friend

    Love Neowin? Tell a friend!