Created
July 5, 2015 00:42
-
-
Save cbertelegni/83f275df2a7a43e34860 to your computer and use it in GitHub Desktop.
Simple method javascript for set and get permalinks
This file contains hidden or 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
var context = { | |
'estado1': null, | |
'estado2': 12 | |
} | |
var permalink: { | |
set:function(){ | |
location.hash = JSON.stringify(context); | |
}, | |
get: function(){ | |
var u = location.hash.replace("#", ""); | |
if(u){ | |
var o = JSON.parse(u); | |
for(var k in o){ | |
context[k] = o[k]; | |
} | |
} | |
} | |
} | |
// example | |
permalink.set() // page.html#{"estado1":null,"estado2":12} | |
var obj = permalink.get() | |
obj // {"estado1":null,"estado2":12} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment