在默认浏览器中打开TWebBrowser链接 [英] Opening TWebBrowser link in default browser

查看:90
本文介绍了在默认浏览器中打开TWebBrowser链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在 TWebBrowser 控件中显示从网络加载的小横幅.这个横幅实际上是一个包含图像的HTML页面;当用户点击图片时,他们将被带到我们当前正在运行的促销活动中.

My application displays a small banner loaded from the web in a TWebBrowser control. This banner is actually a HTML page including an image; when the users click the image it takes them to the promotional campaign we're currently running.

这里的不好的地方是,当单击TWebBrowser中的链接时,活动页面是在Internet Explorer中打开的,而不是在其默认浏览器中打开的.我知道发生这种情况是因为 TWebBrowser 是基于IE的控件,但是有没有办法在用户选择的浏览器中打开链接?

The bad thing here is that when clicking the link in TWebBrowser, the campaign page is opened in Internet Explorer, not in their default browser. I know this happens because TWebBrowser is a IE-based control, but is there a way to open the link in users' browser of choice?

谢谢.

推荐答案

OnBeforeNavigate2 事件中,检查所请求的URL,如果它是您要启动的URL,则 Stop()当前导航,并调用 ShellExecute()在用户的默认外部浏览器中启动URL.

In the OnBeforeNavigate2 event, check the requested URL and if it is one that you want to launch then Stop() the current navigation and call ShellExecute() to launch the URL in the user's default external browser.

procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject; pDisp: IDispatch; var URL: Variant; var Flags: Variant; var TargetFrameName: Variant; var PostData: Variant; var Headers: Variant; var Cancel: WordBool);
begin  
  if (URL should be launched) then
  begin
    Cancel := True;
    WebBrowser1.Stop;
    ShellExecute(0, nil, PChar(String(Url)), nil, nil, SW_SHOWNORMAL);
  end;
end;

这篇关于在默认浏览器中打开TWebBrowser链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆