RichieHindle
RichieHindle

Reputation: 281515

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

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.

Upvotes: 0

Views: 1875

Answers (2)

RichieHindle
RichieHindle

Reputation: 281515

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.

Upvotes: 2

Chad Grant
Chad Grant

Reputation: 45382

My original answer was the exact opposite of what you wanted.

I cannot replicate what you are experiencing but I am not using a Browser Control.

I would try adding a script to the html or a hidden frame/iframe and wrap the call so the browser executes it in the wrapper script.

Script based Navigates should not enter history, it took me awhile to come up with a way to hack IE to actually add history items with the click() event trigger from my original answer.

<script>
    function GoTo(url) {
        location = url;
    }
</script>

Upvotes: 0

Related Questions