ブラウザでホストされているアプリケーション(XBAP)が実行されているブラウザのバージョン(IE6、IE7、IE8など)を確認することはできますか?XBAP内からブラウザーのバージョンを確認したい。
1960 次
3 に答える
2
Microsoft フォーラムの助けを借りて、最終的に機能する方向に導かれました。以下、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;
}
于 2010-04-12T07:19:22.017 に答える
1
WPF ではなく Silverlight を意味していると思いますか? (似ていますが、これらは別個のテクノロジです)。
クラスを見てみましょうSystem.Windows.Browser.BrowserInformation
具体的には
System.Windows.Browser.BrowserInformation.BrowserVersion
上記の MSDN ページから:
using System;
System.Windows.Controls を使用します。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";
}
}
于 2010-04-08T10:34:08.317 に答える