2016-09-06 20 views
0

WebBrowserに「reload」イベントはありますか?Webブラウザの変更イベントでC#

私は、ページ自体がリロードされたときにコンソールにデバッグメッセージを出力する何らかのイベントを意味します。

あなたはまた、ポストバックに基づいて行うことができます
+0

はい。 https://www.google.com/search?q=c-sharp+refresh+page&ie=&oe= –

+0

lolを見て、再び投稿を読んでください。 –

+0

ああ....ページがリロードされていないときは、ページがリロードされます。申し訳ありません –

答えて

-1
protected void Page_Load(object sender, EventArgs e) 
    { 
     if (Session["NextLoad"] == true) 
     { 
      //save to log 
     }else 
     { 
      Session["NextLoad"] = true; 
     } 

    } 

..

protected void Page_Load(object sender, EventArgs e) 
    { 
     if (IsPostBack) 
     { 
      //save to log 
     } 
    } 

それとも、あなたはセッションを超えて存続することとクッキーを使用したくない、データベースおよびチェックに利用者のIPを固執必要がある場合それが次の訪問時に存在するかどうかを調べる。そうであれば、ログを書きます。

protected void Page_Load(object sender, EventArgs e) 
    { 
     if(!does_User_IP_Exist_In_DB(user_IP)){ 
      add_User_IP(user_IP); 
     }else{ 
      write_To_Log(); 
     } 
    } 

FRAMESを使用すると変更されます。あなたは、使用したいと思うでしょう:

// event handler for when a document (or frame) has completed its download 
Timer m_pageHasntChangedTimer = null; 
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { 
// dynamic pages will often be loaded in parts e.g. multiple frames 
// need to check the page has remained static for a while before safely saying it is 'loaded' 
// use a timer to do this 

// destroy the old timer if it exists 
if (m_pageHasntChangedTimer != null) { 
    m_pageHasntChangedTimer.Dispose(); 
} 

// create a new timer which calls the 'OnWebpageReallyLoaded' method after 200ms 
// if additional frame or content is downloads in the meantime, this timer will be destroyed 
// and the process repeated 
m_pageHasntChangedTimer = new Timer(); 
EventHandler checker = delegate(object o1, EventArgs e1) { 
    // only if the page has been stable for 200ms already 
    // check the official browser state flag, (euphemistically called) 'Ready' 
    // and call our 'OnWebpageReallyLoaded' method 
    if (WebBrowserReadyState.Complete == webBrowser.ReadyState) { 
     m_pageHasntChangedTimer.Dispose(); 
     OnWebpageReallyLoaded(); 
    } 
}; 
m_pageHasntChangedTimer.Tick += checker; 
m_pageHasntChangedTimer.Interval = 200; 
m_pageHasntChangedTimer.Start(); 
} 

OnWebpageReallyLoaded() { 
/* place your harvester code here */ 
} 
から撮影

HTML - How do I know when all frames are loaded?

0

あなたはDocumentCompletedイベントを聞くと、コンソールに印刷することができます。このイベントは、ドキュメントのダウンロードが完了するたびに開始されるため、1つのURLに対して複数回起動する可能性があります。 DocumentCompletedのUrlプロパティを確認してURLと比較してください。

は、デバッグ用のメッセージを印刷するには:

System.Diagnostics.Debug.WriteLine("Send to debug output."); 

編集: さらに詳しい情報: https://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documentcompleted(v=vs.110).aspx

+0

ありがとうございますが、私は事、このイベントはいくつかのフレームを含むページでは動作しません。このフレームでページを読み込むと、DocumentCompletedについての情報が3回取得されています。 –

+0

さて、あなたはあなたの質問にもっと明示する必要があります。あなたはWPFやWindows.Formsのようないくつかのコードサンプルを置いて、プラットフォームに関する問題と情報を解決しようとします。問題の例を教えてもらえますか? – user1845593

+0

申し訳ありません。私はWindows.Formを使用していて、いくつかのフレームが含まれているページのDocumentCompletedのイベントをコードしたい。私はそれをする方法を知らない。 –

関連する問題