R – IE WebBrowser control: Prevent URLs going into the IE address bar URL history

internet-explorerwebbrowser-controlwindows

I have a Windows app that embeds the IE WebBrowser control, and runs a local webserver to serve content it. The URLs I load in are only meaningful within the application, and not valid after the application exits. They're never visible to the user. They look like this:

http://127.0.0.1:1234/something.html

where 1234 is a random port number for that session.

But these URLs are appearing the IE browser's address bar history – when I type "1" into Internet Explorer's address bar, a dropdown appears with all my URLs in it. They are useless in that context.

So, my question is: how do I prevent my URLs polluting that dropdown?

A little more information: I'm loading the URLs using window.location.href = URL, rather than via the Navigate method, so navNoHistory isn't an option (and I think that refers to the Back/Forward history anyway).

I've also tried deleting the URLs after the fact using IUrlHistoryStg::DeleteUrl(), but it doesn't work (it returns success but has no effect) – any tips on making that work would be gratefully received.

Best Solution

I've now made this work with IUrlHistoryStg::DeleteUrl() - if you call it immediately after asking the control to load a URL, it doesn't work. I'm guessing that's because the control doesn't add the URL to the history until it's finished loading the document.

By calling IUrlHistoryStg::DeleteUrl() later on, I can remove the URLs from the history.

I'd still rather they didn't get there in the first place, though.

Related Question