Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  66] [ 3]  / answers: 1 / hits: 23902  / 12 Years ago, mon, october 15, 2012, 12:00:00

I am trying to make an application in phonegap. I have made a custom.js javascript file which have some functions as



function func1(){....}
function func2(){....}


All these functions will be used in two different html pages. In first HTML page,I am using a variable in func1 which is doing some operation. In second page, I want to access it in func2 in the state in which he was in func1. But i am unable to do it. I am including custom.js in both html pages. I have read that javascript files get reset/refresh when used in multiple pages. Can anybody give me an example that how to save the state of variable in func1 and then access that variable in func2 (in different HTML page) in the state in which he was in func1. i have also read about view state. but it is not working either for me. Please help...


More From » html

 Answers
5

Store the values in localstorage and reference it from there.



function first() {
localStorage.setItem('myItem', something you want to store);
}

function second() {
myValue = null;
if (localStorage.getItem('myItem')) {
myValue = localStorage.getItem('myItem');
}
}

[#82545] Saturday, October 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rociom

Total Points: 287
Total Questions: 88
Total Answers: 101

Location: Oman
Member since Wed, Nov 17, 2021
3 Years ago
;