问题
I have a Chrome App with a webview that has a 'persistent partition', I need to have a button that will clear all the data saved in that webview's partition. I've tried the following solution based on the official google samples but I can't get it to work
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');});
}
The webview in the app is like this:
<webview id="webview-window" src="http://www.google.ca" partition="persist:cache1">
I'm getting the error: "uncaught typeError:...clearData is not a function" whenever I press the button that runs the clearCache() function above.
I've never worked with webviews this way before so any extra explanation would be much appreciated.
回答1:
You may want to check your method call syntax. May be more of a context problem.
From the documentation it appears that the call for clearData is directly on to the webview itself.
<webview>.clearData( ClearDataOptions options, ClearDataTypeSet types, function callback)
Also, this SO post might prove useful for more understanding. Short variable for DOM methods
来源:https://stackoverflow.com/questions/35995953/clearing-webview-data