procedure TForm1.WebBrowser1BeforeNavigate2(ASender: TObject; const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData, Headers: OleVariant; var Cancel: WordBool); var myurl,tstr:string; Stpos,len:Integer; begin if WebBrowser1.ReadyState=READYSTATE_COMPLETE then //判断页面是否加载完成 begin myurl:=string(URL); //获取URL Stpos:=LastDelimiter('#',myurl); //获取URL中 #向后的字符个数 len:=Stpos-1; //字符长度减一 tstr:=Copy(myurl,stpos+1,len); //组合过滤后子字符 //判断用户点击了那个链接 if tstr='caigou' then begin ShowMessage('caigou'); Cancel:=True; Exit; end; if tstr='caiwu' then begin ShowMessage('caiwu'); Cancel:=True; Exit; end; if tstr='xiaoshou' then begin ShowMessage('xiaoshou'); Cancel:=True; Exit; end; if tstr='cangku' then begin ShowMessage('cangku'); Cancel:=True; Exit; end; if tstr='renshi' then begin ShowMessage('renshi'); Cancel:=True; Exit; end; end; end;
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/186636.html