トップ回答者
WebBrowserでユーザ行動を追跡するイベントとは?

質問
-
Jeshonと申します。
WebBrowserでユーザの行動をログとして追跡したいですが、下記のことをやりたいです。
①ユーザがWebBrowserに配置された任意TextboxにFocusして、データを入力する。入力開始または完了した時点で、何を入力したのか取得したい。
②ユーザがWebBrowserにあるリンクをクリックして、クリック開始または完了した時点で、リンク名を取得したい。
問題点としては、
①WebBrowser何のイベントで上記のユーザ行動を把握できるか不明です。
②こんなイベントがない場合、代替手段があるか不明です。
ご教授のほど、よろしくお願いします。
回答
-
Jeshon さんからの引用 コントロールにFocusを取得または失った時点でコントロールの名前を取得できれば解決になるのですが・・・・・
それだけでよければ、HtmlDocument.LosingFocus イベントと HtmlDocument.Focusing イ
ベントを使って、そのハンドラで以下のようにすればフォーカスを失う/得る EtmlElement の
name 属性が取得できますが、どうですか。
Code Snippetprivate void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Focusing += new HtmlElementEventHandler(Document_Focusing);
webBrowser1.Document.LosingFocus += new HtmlElementEventHandler(Document_LosingFocus);
}private void Document_LosingFocus(Object sender, HtmlElementEventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("FromElement: {0}", (e.FromElement != null) ? e.FromElement.GetAttribute("name") : "null");
sb.AppendLine();
sb.AppendFormat("ToElement: {0}", (e.ToElement != null) ? e.ToElement.GetAttribute("name") : "null");
sb.AppendLine();
MessageBox.Show(sb.ToString(), "LosingFocus Event");
}private void Document_Focusing(Object sender, HtmlElementEventArgs e)
{
StringBuilder sb = new System.Text.StringBuilder();
sb.AppendFormat("FromElement: {0}", (e.FromElement != null) ? e.FromElement.GetAttribute("name") : "null");
sb.AppendLine();
sb.AppendFormat("ToElement: {0}", (e.ToElement != null) ? e.ToElement.GetAttribute("name") : "null");
sb.AppendLine();
MessageBox.Show(sb.ToString(), "Focusing Event");
}
すべての返信
-
すみません、もしかして、WebBrowser コントロールの話ですよね?
ずいぶん外れたことを言ってしまって申し訳ありません。
だとしますと、↓が参考になりませんか?
WebBrowser.Navigated イベント
http://msdn.microsoft.com/ja-jp/library/system.windows.forms.webbrowser.navigated(VS.80).aspx
なんだか、すでにごらんになってそうな気がしますが、一度ご確認ください。
-
大久保さん
情報ありがとうございます。
追跡したいのはWebBrowserで開いたHTMLページにあったの任意コントロール、たとえばTextBox、Buttonなど。
VS.netのコントロールではないです。
今まではHTMLページにActiveしているコントロール名を取得できますが、でもコントロールにFocusを取得または失った時点は判断できないので、コントロール名を取得するタイミングが分からないです。それで、コントロールにFocusを取得または失った時点でWebBrowserで上記のことを判別できるイベントまたは解決策を探しています。
一応ひとつ案としてはServiceとして、1秒間隔でActiveしているコントロール名を取得する方向を考えていますが、あまりよろしくないので別策を考えています。それで別策としては、コントロールにFocusを取得または失った時点でコントロールの名前を取得できれば解決になるのですが・・・・・
説明不足ですみませんが、
よろしくお願いします。 -
Jeshon さんからの引用 コントロールにFocusを取得または失った時点でコントロールの名前を取得できれば解決になるのですが・・・・・
それだけでよければ、HtmlDocument.LosingFocus イベントと HtmlDocument.Focusing イ
ベントを使って、そのハンドラで以下のようにすればフォーカスを失う/得る EtmlElement の
name 属性が取得できますが、どうですか。
Code Snippetprivate void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.Focusing += new HtmlElementEventHandler(Document_Focusing);
webBrowser1.Document.LosingFocus += new HtmlElementEventHandler(Document_LosingFocus);
}private void Document_LosingFocus(Object sender, HtmlElementEventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("FromElement: {0}", (e.FromElement != null) ? e.FromElement.GetAttribute("name") : "null");
sb.AppendLine();
sb.AppendFormat("ToElement: {0}", (e.ToElement != null) ? e.ToElement.GetAttribute("name") : "null");
sb.AppendLine();
MessageBox.Show(sb.ToString(), "LosingFocus Event");
}private void Document_Focusing(Object sender, HtmlElementEventArgs e)
{
StringBuilder sb = new System.Text.StringBuilder();
sb.AppendFormat("FromElement: {0}", (e.FromElement != null) ? e.FromElement.GetAttribute("name") : "null");
sb.AppendLine();
sb.AppendFormat("ToElement: {0}", (e.ToElement != null) ? e.ToElement.GetAttribute("name") : "null");
sb.AppendLine();
MessageBox.Show(sb.ToString(), "Focusing Event");
} -
SurferOnWwwさん
ご教授ありがとうございます。
一応行き詰ったどころが解決しましたので、これから本番開発に入ります。
ご丁寧に教えていただき、誠にありがとうございます。
今後、開発中にまだ何か不明な点がありましたら、ご教授のほどよろしくお願いします。