You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Delphi中使用TMS Web Core实现图片跳转至网站

实现TWebImageControl和TWebLinkLabel的点击跳转功能

针对TWebImageControl的实现步骤

  1. 在设计界面添加TWebImageControl,通过ImageURL属性设置要显示的图片路径。
  2. 双击组件的OnClick事件,写入以下代码:
procedure TForm1.WebImageControl1Click(Sender: TObject);
begin
  // 在新标签页打开目标网站
  window.open('https://你的目标网址.com', '_blank');
  // 若需在当前页面跳转,替换为:window.location.href := 'https://你的目标网址.com';
end;

针对TWebLinkLabel的实现步骤

如果不想用组件自带的Link属性,而是通过OnClick事件实现跳转:

  1. 在设计界面添加TWebLinkLabel,设置Caption为你需要显示的文字。
  2. 双击组件的OnClick事件,写入以下代码:
procedure TForm1.WebLinkLabel1Click(Sender: TObject);
begin
  // 在新标签页打开目标网站
  window.open('https://你的目标网址.com', '_blank');
  // 若需在当前页面跳转,替换为:window.location.href := 'https://你的目标网址.com';
end;

注意事项

  • window.open是JavaScript原生API,在TMS Web Core环境中可直接调用,_blank参数指定在新标签页打开链接。
  • 目标网址必须包含完整前缀(如https://),否则会被当作相对路径处理,导致跳转失败。

内容的提问来源于stack exchange,提问作者Moshelly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 04:52:02