自动重定向到扫描的链接

问题描述 投票:0回答:1

我在我的应用程序中使用ngx-zxing模块在我的离子角应用程序中实现了一个qr扫描仪。

扫描后,我想将用户重定向到扫描链接直接重定向的页面,无需用户手动干预。

code.html

<!-- code for qr scanner alreday implemented, the result is present in the below code -->

<div>
<a href="{{qrResult}}" #link></a>
</div>

code.ts

//all imports and components are written.I am directly implementing the function definition in in which I have to redirect to the link.


handleQrCodeResult(result: string) {
    console.log("Result", result);
    this.qrResult = result;
    this.clickLink();

  }

clickLink(){
  let el = (<HTMLImageElement>document.getElementById('link'))
    console.log('el', el); // this is returning null.
el.click();
 }
javascript angular typescript ionic2
1个回答
1
投票

看看,下面的代码不需要人工交互

handleQrCodeResult(result: string) {
  console.log("Result", result);
  this.qrResult = result;

  // This line will redirect to the link you want
  window.location.href = "Insert link here";    // Maybe: document.getElementById('link')
}

说明

  1. window.location.href = "URL";如果您将url分配给此变量,浏览器将重定向到同一页面中的url,不会打开新选项卡
  2. window.open("URL", "_blank");使用它在新标签页中打开网址
© www.soinside.com 2019 - 2024. All rights reserved.