Skip to content

Instantly share code, notes, and snippets.

@properapp
Created October 18, 2013 00:51
Show Gist options
  • Save properapp/7034835 to your computer and use it in GitHub Desktop.
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.
# 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