webbrowser如何获取当前的链接URL(50分)

  • 主题发起人 主题发起人 snpl
  • 开始时间 开始时间
S

snpl

Unregistered / Unconfirmed
GUEST, unregistred user!
webbrowser如何获取当前的链接URL
谢谢
 
LocationURL ?
 
如:一个登录按钮所指向的URL
 
WebBrowser1StatusTextChange(Sender: TObject;
const Text: WideString);
Text:可能就是你想要的内容
 
vardo
c:IHTMLDocument2;
all:IHTMLElementCollection;
i:integer;
item:OleVariant;
begin
do
c:=WebBrowser1.Document as IHTMLDocument2;
all:=doc.Get_links;
for i:=0 to all.length-1do
begin
item:=all.item(i,varempty);

Memo1.Lines.Add(item.href);
//所有链接
end;
 
想做像速达一样的导航图 ,点击页面,然后出现相应的窗体
 
procedure TMainFrm.WebBrowser1BeforeNavigate2(ASender: TObject;
const pDisp: IDispatch;
var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant;
var Cancel: WordBool);
begin
//URL参数就是链接URL。根据这个做你的实际动作。如打开某个模块的窗体……
Cancel:=True;//取消原来链接
end;
 
以下代码来自我的程序:
procedure TFrmMain.WebBrowserBeforeNavigate2(Sender: TObject;
const pDisp: IDispatch;
var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant;
var Cancel: WordBool);
var
ResLeft: string;
sCaptionIn, sCaption, sCaptionLeft: WideString;
sDll, sDllLeft: string;
sFrame: string;
begin
//[caption]商品信息维护[dll]pPosDLL.dll[frame]FrmItem
if UpperCase(Copy(URL, 1, 6)) = 'URL://' then
begin
URL := Copy(URL, 7, Length(URL) - 1);
ShellExecute(handle, 'open', 'iexplore.exe',
PChar(ExtractFilePath(Application.ExeName) +
'ReportWeb/' + string(URL)), nil, SW_MAXIMIZE);
Cancel := True;
end;

if UpperCase(Copy(URL, 1, 7)) = 'HTTP://' then
begin
// URL := Copy(URL, 7, Length(URL) - 1);
ShellExecute(handle, 'open', 'iexplore.exe',
PChar(string(URL)), nil, SW_MAXIMIZE);
Cancel := True;
end;

if UpperCase(Copy(URL, 1, 6)) = 'RES://' then
begin
ResLeft := Copy(URL, 7, Length(URL) - 1);
// Caption
sCaptionIn := Copy(ResLeft, 1, Pos('[dll]', ResLeft) - 1);
sCaption := Trim(Copy(sCaptionIn, Length('[caption]') + 1,
Length(sCaptionIn) - 1));
if Copy(sCaption, 1, 2) = 'n]' then
begin
sCaption := Copy(sCaption, 3, Length(sCaption) - 1);
end;

sCaptionLeft := Copy(ResLeft, Pos('[dll]', ResLeft) + Length('[dll]'),
Length(ResLeft) - 1);
// Dll
sDll := Trim(Copy(sCaptionLeft, 1, Pos('[frame]', sCaptionLeft) - 1));
sDllLeft := Copy(ResLeft, Pos('[frame]', ResLeft) + Length('[frame]'),
Length(ResLeft) - 1);
// Frame
sFrame := Trim(StringReplace(sDllLeft, '/', '', []));
// 判断权限
// if not Right.GetRight(gUserInfo.UserID, sDll, sFrame) then
// begin
// Cancel := True;
// raise Exception.Create('权限不足,请与管理员联系!');
// end;
try
DllImport.ImportDllFrame(sDll, sFrame, sCaption,
NoteBook, TabControl1);
PnlTabContrl.Visible := True;
except
on E: Exceptiondo
begin
Cancel := True;
raise Exception.Create(E.Message);
end;
end;

DllImport.ParentResize(Self.Width - 5,
Self.Height - StatusBar.Height - PnlLogo.Height - 30);
Cancel := True;
end;
end;
 
后退
顶部