Embedded Web Browser阻止彈出廣告、視窗等技術

來源:互聯網
上載者:User
  • 檢測快顯視窗是不是自動彈出廣告

在TEmbeddedWB控制項的OnStatusTextChange事件處理函數中,儲存Text參數。如果新視窗不是自動彈出而是由使用者點選連結彈出,該參數中會儲存新視窗中頁面的URL。於是可以通過比較URL來進行判斷。

procedure TForm1.wbMainStatusTextChange (ASender: TObject;  const Text: WideString);begin  mStatusText := Text;end;

 

  • 阻止預設會彈出的新視窗

在TEmbeddedWB控制項的OnNewWindow3事件觸發的函數中,臨時取消新視窗的建立,在判斷新視窗不是廣告以後,由當前視窗中的瀏覽器控制項訪問彈出的網頁,從而阻止了網頁的彈出。

procedure TForm1.wbMainNewWindow3 (ASender: TObject;  var ppDisp: IDispatch; var Cancel: WordBool; dwFlags: Cardinal;  const bstrUrlContext, bstrUrl: WideString);begin  Cancel:=true;  if (bstrUrl = mStatusText) then//使用者點擊  begin    wbMain.Navigate(bstrUrl);  end;end;

 

  • 判斷整個網頁已讀取完畢(排除frame/iframe的影響)

當TEmbeddedWB控制項的OnDocumentComplete事件觸發時,說明網頁已經讀取完成;但是如果網頁中含有frame/iframe元素,在每個frame/iframe中的網頁讀取完成時都會觸發OnDocumentComplete事件。為了排除這些frame/iframe的幹擾,在OnDocumentComplete事件觸發時,需要增加一個判斷,即判斷是不是整個網頁完成。

procedure TForm1.wbMainDocumentComplete (ASender: TObject;  const pDisp: IDispatch; var URL: OleVariant);begin              if (wbMain.Application = pDisp) then  begin    // TODO: 此處添加需要的代碼  end;end;
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.