【问题标题】:How to redirect external website URL in Anglar 11?如何在 Angular 11 中重定向外部网站 URL?
【发布时间】:2021-10-20 04:06:03
【问题描述】:

我尝试在 Angular 中单击按钮时打开重定向外部网站,但它不起作用,请帮助

<button  [routerLink]="www.google.com" >
   Goto google
  </button>

【问题讨论】:

标签: angular angular-material angular-ui-router


【解决方案1】:

您也可以使用锚标记,将target 用作_blank 将导致它在新选项卡中打开。如果您需要重定向到同一选项卡,请将其删除。

 <a href="www.google.com" target="_blank">Go to Google</a>

如果您想使用按钮,请尝试以下操作:

<button onclick="window.location.href='https://google.com';" value="Go to Google" />

【讨论】:

  • 如何在按钮中重定向
【解决方案2】:
<a href="https://www.google.com/">Goto google</a>

这会将用户重定向到 Google 网站

[routerLink] 用于内部 URL(在您的 Angular 应用程序中)

【讨论】:

  • 可以自行设置链接按钮吗?
  • 对不起,我没有得到你的问题。你想用按钮标签代替锚标签吗?
  • 是的,我想使用按钮标签而不是锚标签
  • 在这种情况下定义一个点击事件并在您的点击事件中使用window.location = "https://www.google.com"。这会将您的页面重定向到 Google。
猜你喜欢
  • 1970-01-01
  • 2018-06-24
  • 1970-01-01
  • 2018-09-07
  • 2017-04-13
  • 2015-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多