最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Clear Phonegap's InAppBrowser Cache Programmatically - Stack Overflow

programmeradmin3浏览0评论

I am using Oauth 2.0 for Google authorization into a hybrid app. I am using PhoneGap's InAppBrowser API and it works perfectly; however, I want to be able to clear the cache of the InAppBrowser after someone clicks the local logout button. I have tried adding "clearcache=yes" and "clearsessioncache=yes", but they do not seem to do anything. Without clearing the cache when someone tries to log back in it validates the token with the previously signed in account. The only way I can sign out is to keep trying to login until I get the Google permissions screen and can manually logout. Is there a way I can delete everything associated to the InAppBrowser programmatically?

Thanks

I am using Oauth 2.0 for Google authorization into a hybrid app. I am using PhoneGap's InAppBrowser API and it works perfectly; however, I want to be able to clear the cache of the InAppBrowser after someone clicks the local logout button. I have tried adding "clearcache=yes" and "clearsessioncache=yes", but they do not seem to do anything. Without clearing the cache when someone tries to log back in it validates the token with the previously signed in account. The only way I can sign out is to keep trying to login until I get the Google permissions screen and can manually logout. Is there a way I can delete everything associated to the InAppBrowser programmatically?

Thanks

Share Improve this question asked Dec 3, 2014 at 2:00 benjipelletierbenjipelletier 6635 gold badges11 silver badges30 bronze badges 2
  • when you are calling clearcache or clearsessioncache ? before re-opening the InAppbrowser ? – AAhad Commented Dec 3, 2014 at 5:10
  • which device you are using? clearcache or clearsessioncache is only for Android. – AAhad Commented Dec 3, 2014 at 5:16
Add a comment  | 

5 Answers 5

Reset to default 13

As said: clearcache or clearsessioncache is only for Android. read this API Doc

In case of Android so before re-opening:

window.open("domain.com", "_blank", "location=no,clearsessioncache=yes"); 

For iOS: check this out.

Alternatives:

  1. Clear the session cookie via javascript directly or indirectly (check this - JQuery Cookie clearing )
  2. Phonegap/Cordova plugin that allows you to clear cookies of the webview...see this

The selected answer is out of date, you can now use the clearsessioncache flag in both iOS and Andriod. See documentation here:

https://github.com/apache/cordova-plugin-inappbrowser

So the correct solution is to just use

window.open("domain.com", "_blank", "location=no,clearsessioncache=yes"); 

In any case. Also note

The options string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive.

I think best way to logout from google in the inAppBrowser is open the url

'https://mail.google.com/mail/logout?hl=en'

from it, it will automatically log you out from google redirecting you to login page. If you need to do this by any button click of your app, you can open the inAppBrowser hidden.

window.open('https://mail.google.com/mail/logout?hl=en', '_blank', 'hidden=yes')

Also you can do another thing you can open this url in hidden mode before every time you call the Oauth url. It will make sure your previous session has been logged out letting you provide different login Id.

iOS users please add this line to config file

iOS Quirks Since the introduction of iPadOS 13, iPads try to adapt their content mode / user agent for the optimal browsing experience. This may result in iPads having their user agent set to Macintosh, making it hard to detect them as mobile devices using user agent string sniffing. You can change this with the PreferredContentMode preference in config.xml.

<preference name="PreferredContentMode" value="mobile" />

The example above forces the user agent to contain iPad. The other option is to use the value desktop to turn the user agent to Macintosh.

You may want to add a meta tag for no-cache in the head.

That worked for me.

发布评论

评论列表(0)

  1. 暂无评论