清除 Webview 数据
Clearing Webview Data
我有一个 Chrome 应用程序,其网页视图具有 'persistent partition',我需要一个按钮来清除保存在该网页视图分区中的所有数据。我已经根据官方 google 示例尝试了以下解决方案,但无法正常工作
var clearDataType = {
appcache:true,
cookies: true,
fileSystems: true,
indexedDB: true,
localStorage: true,
webSQL: true,
}
function clearCache() {
document.getElementById('webview-window').clearData(
{ since: 0 }, // Remove all browsing data.
clearDataType, function() {console.log('cache cleared');});
}
应用中的webview是这样的:
<webview id="webview-window" src="http://www.google.ca" partition="persist:cache1">
我收到错误:"uncaught typeError:...clearData is not a function" 每当我按下运行上面的 clearCache() 函数的按钮时。
我以前从未以这种方式使用过 webview,因此非常感谢任何额外的解释。
您可能需要检查您的方法调用语法。可能更多是上下文问题。
从 documentation 看来,对 clearData 的调用直接在 webview 本身上。
<webview>.clearData( ClearDataOptions options, ClearDataTypeSet types, function callback)
此外,此 SO post 可能有助于加深理解。
Short variable for DOM methods
我有一个 Chrome 应用程序,其网页视图具有 'persistent partition',我需要一个按钮来清除保存在该网页视图分区中的所有数据。我已经根据官方 google 示例尝试了以下解决方案,但无法正常工作
var clearDataType = {
appcache:true,
cookies: true,
fileSystems: true,
indexedDB: true,
localStorage: true,
webSQL: true,
}
function clearCache() {
document.getElementById('webview-window').clearData(
{ since: 0 }, // Remove all browsing data.
clearDataType, function() {console.log('cache cleared');});
}
应用中的webview是这样的:
<webview id="webview-window" src="http://www.google.ca" partition="persist:cache1">
我收到错误:"uncaught typeError:...clearData is not a function" 每当我按下运行上面的 clearCache() 函数的按钮时。
我以前从未以这种方式使用过 webview,因此非常感谢任何额外的解释。
您可能需要检查您的方法调用语法。可能更多是上下文问题。
从 documentation 看来,对 clearData 的调用直接在 webview 本身上。
<webview>.clearData( ClearDataOptions options, ClearDataTypeSet types, function callback)
此外,此 SO post 可能有助于加深理解。 Short variable for DOM methods