Clear WebBrowser control browsing history

一个人想着一个人 提交于 2019-12-04 14:27:25

问题


I want to clear WebBrowser control history after WebBrowser completes its browsing.


回答1:


The history state of the System.Windows.Forms.WebBrowse control is internal and cannot be modified directly. All actions are performed via the GoBack and GoForward methods.

You can prevent your users from going backwards and forwards by setting the CanGoBack and CanGoForward properties to false. You would also want to modify the AllowWebBrowserDrop, WebBrowserShortcutsEnabled and IsWebBroserContextMenuEnabled properties as well.

Because history is only exposed through these methods, properties and user actions there is no need to clear the internal history state because the user cannot act on it. Note that session history (i.e. the back/forward buttons) is a separate concept from the "browser history" (what you see in the History panel in IE).

Note that it's possible that WebBrowser instances contained within other programs may write to the Windows user IE history files, however I don't know for certain. If they do I doubt there's anything you can do about that.




回答2:


Actually, there are two types of history. One is "Visited" pages list, and the other is the actual history you see in IE's history user interface.

If you want to remove the visited pages list, you need to use DeleteUrlCacheEntry to delete each item. By looping through using FindFirst/NextUrlCacheEntry API's you can get access to the time and date these items were creates, and therefore only delete the items created after your browser session started and before it was finished.

For FindFirst/NextUrlCacheEntry and DeleteUrlCacheEntry information, there are pre-written codes online that you can use, and then it will be easy for you to create a filter to decide which items you want deleted when you are looping through these cache entries.

Let me know if I can be of further assistance.



来源:https://stackoverflow.com/questions/12197883/clear-webbrowser-control-browsing-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!