Is it possible to find out in what browser version a browser hosted application (XBAP) runs (eg. IE6, IE7 or IE8)? I want to find out the browser version from within the XBAP.
Asked
Active
Viewed 2,057 times
2
-
@Rob: Have you run into a need for this? If so, what is it? – VoidDweller Apr 08 '10 at 13:36
-
For our application we need to have a way to report in what browser version our application is running. The report is generated for support purposes and has all kinds of system information. Unfortunately the browser version does have influence on application behavior. – Rob Apr 13 '10 at 10:42
3 Answers
2
With some help from a Microsoft forum I was led into a direction that finally works. Below a proof of concept in C++.NET (.
using namespace System::Windows::Forms;
[STAThread]
String^ GetBrowserVersion() {
String^ strResult = String::Empty;
WebBrowser^ wb = gcnew WebBrowser();
String^ strJS = "<SCRIPT>function GetUserAgent() { return navigator.userAgent; }</SCRIPT>";
wb->DocumentStream = gcnew MemoryStream( ASCIIEncoding::UTF8->GetBytes(strJS) );
while ( wb->ReadyState != WebBrowserReadyState::Complete ) {
Application::DoEvents();
}
String^ strUserAgent = (String^)wb->Document->InvokeScript("GetUserAgent");
wb->DocumentStream->Close();
String^ strBrowserName = String::Empty;
int i = -1;
if ( ( i = strUserAgent->IndexOf( "MSIE" ) ) >= 0 ) {
strBrowserName = "Internet Explorer";
} else if ( ( i = strUserAgent->IndexOf( "Opera" ) ) >= 0 ) {
strBrowserName = "Opera";
} else if ( ( i = strUserAgent->IndexOf( "Chrome" ) ) >= 0 ) {
strBrowserName = "Chrome";
} else if ( ( i = strUserAgent->IndexOf( "FireFox" ) ) >= 0 ) {
strBrowserName = "FireFox";
}
if ( i >= 0 ) {
int iStart = i + 5;
int iLength = strUserAgent->IndexOf( ';', iStart ) - iStart;
strResult = strBrowserName + " " + strUserAgent->Substring( iStart, iLength );
}
return strResult;
}

Rob
- 165
- 1
- 1
- 11
-
1Good idea, thanks! Using C# and WPF here. I have a WebBrowser control in my code and for the love of God I couldn't find where to get the Browser's version. What I did was use an external html page (same location as my .exe), loaded it as such: WebBrowserMain.Navigate("pack://siteoforigin:,,,/useragent.html"); And from within useragent.html called a method in my program through javascript that collects the user agent info. Thanks a bunch! – Rowan Aug 28 '16 at 02:12
1
I presume you mean Silverlight rather than WPF? (they're separate technologies, though similar).
Take a look at the System.Windows.Browser.BrowserInformation
Class
Specifically
System.Windows.Browser.BrowserInformation.BrowserVersion
From the MSDN page above:
using System;
using System.Windows.Controls; using System.Windows.Browser;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
outputBlock.Text +=
"\nSilverlight can provide browser information:\n"
+ "\nBrowser Name = " + HtmlPage.BrowserInformation.Name
+ "\nBrowser Version = " +
HtmlPage.BrowserInformation.BrowserVersion.ToString()
+ "\nUserAgent = " + HtmlPage.BrowserInformation.UserAgent
+ "\nPlatform = " + HtmlPage.BrowserInformation.Platform
+ "\nCookiesEnabled = " +
HtmlPage.BrowserInformation.CookiesEnabled.ToString() + "\n";
}
}

Mark Pim
- 9,898
- 7
- 40
- 59
-
XBAP (XAML Browser Application) -- Are WPF applications that can be hosted in a browser. http://msdn.microsoft.com/en-us/library/aa970060.aspx – VoidDweller Apr 08 '10 at 12:49
-
No I mean indeed a XAML Browser Application. I think that using your solution introduces a new dependency to Silverlight. Thanks anyway! I found another solution with some help from a a Microsoft forum, see my response to my own question. – Rob Apr 12 '10 at 07:12
-1
int BrowserVer;
using (var wb = new System.Windows.Forms.WebBrowser())
{
BrowserVer = wb.Version.Major;
}

Alexander van Oostenrijk
- 4,644
- 3
- 23
- 37
-
Add more details to explain why and how does this answer the question. – Manoj Choudhari Dec 26 '19 at 10:36