- Check whether an advertisement is automatically displayed in the pop-up window
In the onstatustextchange event processing function of the tembeddedwb control, save the text parameter. If a new window does not pop up automatically but is clicked by the user, the URL on the page in the new window is saved in this parameter. Therefore, you can compare the URL to determine.
procedure TForm1.wbMainStatusTextChange (ASender: TObject; const Text: WideString);begin mStatusText := Text;end;
- Block A new window that will pop up by default
In the function triggered by the onnewwindow3 event of the tembeddedwb control, temporarily cancel the creation of a new window. After judging that the new window is not an advertisement, the browser control in the current window will access the pop-up webpage, in this way, the webpage pop-up is blocked.
Procedure tform1.wbmainnewwindow3 (asender: tobject; var ppdisp: idispatch; var cancel: wordbool; dwflags: Cardinal; const bstrurlcontext, bstrurl: widestring); begin cancel: = true; if (bstrurl = mstatustext) Then // you can click wbin wbmain. navigate (bstrurl); end;
- Determine whether the entire webpage has been read (excluding the impact of frame/iframe)
When the ondocumentcomplete event of the tembeddedwb control is triggered, the webpage has been read. However, if the webpage contains the frame/IFRAME element, the ondocumentcomplete event is triggered when the webpage reading in each frame/iframe is complete. To eliminate the interference of these frame/iframe, you need to add a judgment when the ondocumentcomplete event is triggered to determine whether the entire webpage is complete.
Procedure tform1.wbmaindocumentcomplete (asender: tobject; const Pdisp: idispatch; var URL: olevariant); begin if (wbmain. application = Pdisp) then begin // todo: add the required code end; end here;