Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  13] [ 5]  / answers: 1 / hits: 18829  / 8 Years ago, fri, august 12, 2016, 12:00:00

Is this possible to insert to localstorage or is there other way to store this?



$('#pass_to_score').on('click',function(){

var compressed = function(){
$('.whole_wrap_of_editcriteria').css('display','none');
$('#wrappler').css('display','block');
$('#li_addcriteria').css('display','none');
$('#li_menu1').addClass('active');
$('#home').removeClass('active');
$('#menu1').addClass('active');
$('#title_panel').html('Edit criteria scoring');
}
compressed();
localStorage.setItem('compressed', compressed());
//i also try set as JSON.stringify but its undefined

});

More From » jquery

 Answers
20

I don't know why you'd want that, I would not recommend it, but you can do it using toString.



Store it:



var myFunc = function (){
alert('Hello world!');
};

// Store it as a String
localStorage.setItem('compressedFunc', myFunc.toString());


Later, retrieve it:



var compressedFunc = localStorage.getItem('compressedFunc');

// Convert the String back to a function
var myFunc = eval('(' + compressedFunc + ')');

// Use it
myFunc();

[#61053] Tuesday, August 9, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austonjuancarlosb

Total Points: 238
Total Questions: 89
Total Answers: 99

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;