2013-02-05 21 views
1

尋找讓我的delphi應用程序登錄到一個網站,導航到一個頁面,並自動下載某些文件,解決方案在How do I keep an embedded browser from prompting where to save a downloaded file?,幫助了很多文件下載。twebbrowser在popupwindow下載

最後一個問題是在一個彈出窗口中導航打開的最後一步,有很多解決方案通過實現TWebBrowser.NewWindow2來捕獲彈出窗口,但這些事件似乎都不能與上面的代碼一起工作,如何在上面的代碼中運行twebbrowser.invokeevent?

如果我使用invokeveent和273(newwindow3)的dispID來調用一個函數,我可以twebbwowser.navigate()第二個webbrowser到popupwindow的url。

我的問題是彈出窗口基本上有一行JavaScript的「document.print(parent.parent.opener.thefunction())」第二個twebbrowser沒有引用其父,所以這失敗了。

我可以看到兩種可能的解決方案,獲取TWebBrowser.NewWindow2或3來觸發,修復代碼示例波紋管,LVarArray [0] {const IDispatch},由於某種原因爲空。

procedure TWebBrowser.InvokeEvent(ADispID: TDispID; var AParams: TDispParams); 
      // DispID 250 is the BeforeNavigate2 dispinterface and to the FFileSource here 
      // is stored the URL parameter (for cases, when the IDownloadManager::Download 
      // won't redirect the URL and pass empty string to the pszRedir) 
      //showmessage('test'); 
      var 
     ArgCount : Integer; 
     LVarArray : Array of OleVariant; 
     LIndex : Integer; 
     begin 
     inherited; 
     ArgCount := AParams.cArgs; 
     SetLength(LVarArray, ArgCount); 
     for LIndex := Low(LVarArray) to High(LVarArray) do 
     LVarArray[High(LVarArray)-LIndex] := OleVariant(TDispParams(AParams).rgvarg^[LIndex]); 

     case ADispID of 
      250: FFileSource := OleVariant(AParams.rgvarg^[5]); 

     273: DoNewWindow3(Self, 
     LVarArray[0] {const IDispatch}, 
      WordBool((TVarData(LVarArray[1]).VPointer)^) {var WordBool}, 
      LVarArray[2] {const OleVariant}, 
     LVarArray[3] {const OleVariant}, 
     LVarArray[4] {const OleVariant}); 
      end; 
     end; 

回答

2

我不會直接回答你的問題,因爲我認爲你提出了錯誤的問題。您正在嘗試通過互聯網下載文件,而無需向用戶顯示任何GUI。因此,嵌入式瀏覽器就是錯誤的解決方案。

與其試圖禁止彈出對話框,不如使用從不顯示彈出對話框的工具。我相信你應該做的是使用直接HTTP下載下載文件。有許多不同的方法來實現這一點。例如,Delphi提供的一個非常方便的方法是使用Indy。我相信你需要的組件是TIdHttp

+0

即使下載的文件是生成服務器端? –

+1

是的,這完全沒有區別。這全都只是HTTP。瀏覽器與Indy組件或其他任何機制一樣。 –

+0

好吧,回到繪圖板,然後我想,不知道如何使用直接http下載,如果我不知道的網址,我確實得到上面的代碼無論如何工作,現在只有問題是它下載的ASP頁面不是文件 –