• 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

    • I have a fire n ice theme w my bedroom laptops. one is a red lenovo gaming laptop (fire) and the precision is ice
    • Adobe Acrobat Reader DC 2026.001.21691 by Razvan Serea Adobe Acrobat Reader DC software is the free, trusted standard for viewing, printing, signing, and annotating PDFs. Its the only PDF viewer that can open and interact with all types of PDF content – including forms and multimedia. It’s connected to Adobe Document Cloud – so you can work with PDFs on computers and mobile devices. Adobe Document Cloud is a revolutionary, modern and efficient way to get work done with documents in the office, at home or on-the-go. At the heart of Document Cloud is the all-new Adobe Acrobat DC, which will take e-signatures mainstream by delivering free e-signing with every individual subscription. Document Cloud includes a set of integrated services that use a consistent online profile and personal document hub. With Adobe Document Cloud, people will be able to create, review, approve, sign and track documents whether on a desktop or mobile device. Businesses will be able to take advantage of Document Cloud for enterprise which provides enterprise-class document services that integrate into systems of record such as CRM, HCM, CLM, and CMS, adding speed, efficiency and transparency to getting business done with documents. Adobe Acrobat Reader DC new feature highlights: Work with PDFs from anywhere with the new, free Acrobat DC mobile app for Android or iOS. Select functionality is also available on Windows Phone. Use the new Fill & Sign tool in your desktop software to complete PDF forms fast with smart autofill. Download the free Adobe Fill & Sign mobile app to add the same option to your iPad or Android tablet device. Save money on ink and toner when printing from your Windows PC. Store and access files in Adobe Document Cloud with 5GB of free storage. Get instant access to recent files across desktop, web, and mobile devices with Mobile Link. Sync your Fill & Sign autofill collection across desktop, web, and iPad devices. Adobe PDF Pack premium features includes: Convert documents and images to PDF files. Use your mobile device camera to take a picture of a paper document or form and convert it to PDF. Turn PDFs into editable Microsoft Word, Excel, PowerPoint, or RTF files. Combine multiple files into a single PDF (web only). Get signatures from others with a complete e-signature service. Send, track, and confirm delivery of documents electronically instead of using fax or overnight services (tracking not available on mobile). Store and access files online with 20GB of storage. Download: Adobe Acrobat Reader DC 64-bit | 719.0 MB (Freeware) Link: Adobe Acrobat Reader DC Home Page | Release Notes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Hello, Interesting. I suspect memory and storage costs have slowed the rollout of Windows 11-compatible hardware for some customers. Regards, Aryeh Goretsky
    • Especially considering their console sales have fallen double digits YOY for 4 years, and no one is buying them. If they were losing $50 on every console, losing 15K a year is no big deal to them
    • Counter-point: if someone comes up with a new way of doing things in their homeplace, should they be offered the options of being bought out by a higher-grossing competitor or suffer their tech to be taken over by force? Because those are the options these days when it comes to the big-stakes companies. Don't get me wrong, the DMA has its flaws. All regulations do. But at the moment with Google, Microsoft, Meta etc. they need to be told to back off to prevent a monopoly that would weaken whatever industry they work in. It's the understanding that money doesn't get you anything that you want, and big-tech need to understand that.
  • Recent Achievements

    • First Post
      kinowa earned a badge
      First Post
    • Rookie
      krychek57 went up a rank
      Rookie
    • Grand Master
      Jaybonaut went up a rank
      Grand Master
    • One Year In
      Philsl earned a badge
      One Year In
    • Dedicated
      Scoobystu earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      404
    2. 2
      +Edouard
      172
    3. 3
      PsYcHoKiLLa
      131
    4. 4
      Xenon
      72
    5. 5
      Michael Scrip
      71
  • Tell a friend

    Love Neowin? Tell a friend!