Created
October 18, 2013 00:51
-
-
Save properapp/7034835 to your computer and use it in GitHub Desktop.
Example of using a localStorage check to test if a browser has access to local storage and using the check as a before filter in Iron Router for Meteor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to check localStorage availability | |
hasStorage = -> | |
try | |
mod = new Date | |
localStorage.setItem mod, mod.toString() | |
result = localStorage.getItem(mod) == mod.toString() | |
localStorage.removeItem mod | |
return result | |
checkLocal = localStorage.getItem("whateverIsInLocalStorage") if hasStorage() | |
if checkLocal? | |
Session.set("whatYouNeedInMeteor", checkLocal) | |
else | |
### | |
In this example, I'm pulling the session data set here into a template. On the template side, I | |
return an empty string if the variable below is null or empty. | |
### | |
Session.set("whatYouNeedInMeteor", null) | |
# Route Definitions | |
Router.map -> | |
# HOME | |
@route 'home', | |
path: '/' | |
before: alreadyVisited | |
template: 'home' | |
layoutTemplate: 'publicLayout' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment