【问题标题】:Clearing Webview Data清除 Webview 数据
【发布时间】:2016-06-29 23:42:48
【问题描述】:

我有一个带有“持久分区”的 webview 的 Chrome 应用程序,我需要一个按钮来清除保存在该 webview 分区中的所有数据。我已经根据官方谷歌示例尝试了以下解决方案,但我无法让它工作

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');});
}

app中的webview是这样的:

<webview id="webview-window" src="http://www.google.ca" partition="persist:cache1">

每当我按下运行上述 clearCache() 函数的按钮时,我都会收到错误消息:“未捕获的 typeError:...clearData is not a function”。

我以前从未以这种方式使用过网络视图,因此非常感谢任何额外的解释。

【问题讨论】:

    标签: javascript google-chrome webview google-chrome-app


    【解决方案1】:

    您可能想检查您的方法调用语法。可能更多的是上下文问题。

    documentation 看来,对 clearData 的调用似乎直接针对 webview 本身。

    <webview>.clearData( ClearDataOptions options, ClearDataTypeSet types, function callback)
    

    此外,这篇 SO 帖子可能有助于加深理解。 Short variable for DOM methods

    【讨论】:

    • 不是 document.getElementById('webview-window') 获取 webview 本身吗?我看了你链接的线程,但我得出了同样的结论。我解释错了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多