1

I am trying to convert a website to a phonegap android application. The web server sets the session id on the client as a cookie. This session id has to be maintained for the complete session.

When I move from one page to another ( the second page is a local html file in the app), using href, or window.location, or navigator.app.loadUrl, it loads the second page in a browser, and the cookies get destroyed, so I can't make an valid ajax request from the second page.

I wouldn't prefer putting all the pages in a single html file ( like jquery mobile) . Given that I have seperate html files, how to navigate between them, such that the second page is loaded in the same webview,( so that the cookies are preserved) rather than in a browser. Do I have to create another activity for it ?

Is there any other way of navigation in phonegap, except those mentioned above ? Or is the only way of staying in the same webview is to dynamically load pages using ajax and replace the existing page with them ?

Another possibility is I can parse the session id from the response, store it in the local storage and append with every request. But this cookie is HTTP Read only, so I can't read it using javascript

4

1 回答 1

1

Backbone.js 是一个很棒的工具,它有很好的分页路由功能,hash 会改变,但是你的 js 对象会保持不变,因为页面没有被刷新,试试看。

我认为它比使用 cookie 更好地使用 localStorage,它更容易并且会与您的页面一起使用。

得到通知,即使用户关闭并重新打开您的应用程序,localStorage 仍保留在设备上。

用法:

localStorage.setItem("foo","bar");
console.log(localStorage.getItem("foo")); //Output: bar
于 2013-01-27T01:17:32.753 回答