开发者

How can I differentiate between the .net WebBrowser component and an actual browser?

OK, so we have an online downloads store accessed via our software. Recently we've had requests to allow downloads via normal browsers and it's fairly easy just to slap a download page on. The problem is that it would be confusing to people having two download links, one for the software and one for their web browser, so w开发者_C百科e want to differentiate between the two and only show the relevant download link.

From what I've gathered, the .net WebBrowser component is the same as IE and uses the same User Agent, so we can't use that unless we subclass the WebBrowser in the software to make it use a specific User Agent. It's the more sensible option, but we'd have to roll out another updated version, which is less than ideal.

Are there any other ways to tell if someone's accessing a site via the .net component? My only other alternative is to copy the store to a different address with the different download links and send people there. Again this is doable, but not ideal.


Check if window.external is null. IE implements window.external to have methods like AddSearchProvider where most of time WebBrowser.ObjectForScripting is null.


I'm not sure if there is any better way to do this, but here is one idea... The WebBrowser control has a property Document that gives you access to the DOM object representing the loaded document (after the page is loaded). This object has InvokeScript method that you can use to run some JavaScript in the loaded page.

You could write a simple JavaScript function, say hideWebDownload() that would switch the view to a view used when the application runs locally and invoke it from your WinForms application that hosts the WebBrowser control:

webCtrl.Document.InvokeScript("hideWebDownload");

The default view of the page would show the download link for web and calling this function in the local application would switch the view to local download link.


Have your software pass in an invisible (to the user) value in the querystring of the URL.

Trivial to look if that's present.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜