javascript 以编程方式清除 Phonegap 的 InAppBrowser 缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27262404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 07:14:32  来源:igfitidea点击:

Clear Phonegap's InAppBrowser Cache Programmatically

javascriptcordovacachinginappbrowser

提问by benjipelletier

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?

我正在使用 Oauth 2.0 对混合应用程序进行 Google 授权。我正在使用 PhoneGap 的 InAppBrowser API,它运行良好;但是,我希望能够在有人单击本地注销按钮后清除 InAppBrowser 的缓存。我曾尝试添加“clearcache=yes”和“clearsessioncache=yes”,但它们似乎没有做任何事情。当有人尝试重新登录时不清除缓存,它会使用先前登录的帐户验证令牌。我可以退出的唯一方法是继续尝试登录,直到我获得 Google 权限屏幕并可以手动退出。有没有办法以编程方式删除与 InAppBrowser 关联的所有内容?

Thanks

谢谢

回答by AAhad

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

如前所述:clearcache or clearsessioncache仅适用于Android。阅读这个API 文档

In case of Androidso before re-opening:

如果是Android,那么在重新打开之前:

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

For iOS: check this out.

对于iOS:检查一下

Alternatives:

备择方案:

  1. Clear the session cookie via javascript directly or indirectly (check this- JQuery Cookieclearing )
  2. Phonegap/Cordova pluginthat allows you to clear cookies of the webview...see this
  1. 通过 javascript 直接或间接清除会话 cookie(检查这个- JQuery Cookieclearing)
  2. Phonegap/Cordova插件,可让您清除web 视图的cookie...请参阅此内容

回答by user917170

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

所选答案已过时,您现在可以clearsessioncache在 iOS 和 Andriod 中使用该标志。请参阅此处的文档:

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

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.

选项字符串不能包含任何空格,并且每个功能的名称/值对必须用逗号分隔。功能名称不区分大小写。

回答by Kishore Barik

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

我认为在 inAppBrowser 中从 google 注销的最佳方法是打开 url

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

' 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.

从中,它会自动将您从谷歌注销,将您重定向到登录页面。如果您需要通过单击应用程序的任何按钮来执行此操作,您可以打开隐藏的 inAppBrowser。

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

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.

你也可以做另一件事,你可以在每次调用 Oauth url 之前以隐藏模式打开这个 url。它将确保您之前的会话已被注销,让您提供不同的登录 ID。

回答by jjyepez

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

您可能希望在head 中为 no-cache 添加元标记。

That worked for me.

那对我有用。