Reputation: 159
I have a website which persists user information in browser localStorage so user doesn't have to login again. Problem is, browser is differentiating the URL as such with www and without it and in the aftermath considers it as a different URL and ignores localStorage. Is there a way that for browser website remains the same either user lands with www or without it?
Upvotes: 0
Views: 56
Reputation: 530
localStorage is also the same as globalStorage[location.hostname], with the exception of being scoped to an HTML5 origin (scheme + hostname + non-standard port) and localStorage being an instance of Storage as opposed to globalStorage[location.hostname] being an instance of StorageObsolete which is covered below. For example, http://example.com is not able to access the same localStorage object as https://example.com but they can access the same globalStorage item. localStorage is a standard interface while globalStorage is non-standard so you shouldn't rely on these.
Essentially it seems the answer is no unless you manually refer to a different hostname through globalStorage and unfortunately that's not particuarly reliable.
As an alternative could you simply redirect all traffic for www.hostname.com to hostname.com or vice-versa instead of trying to solve the problem in browser?
Upvotes: 1