【问题标题】:redirect to the scanned link automatically自动重定向到扫描的链接
【发布时间】:2018-03-02 11:08:31
【问题描述】:

我在我的 ionic-angular 应用程序中使用 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】:

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

    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"); 使用它在新标签页中打开网址

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-31
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-26
      相关资源
      最近更新 更多