gpt4 book ai didi

javascript - 自动重定向到扫描的链接

转载 作者:行者123 更新时间:2023-12-03 02:23:12 26 4
gpt4 key购买 nike

我在我的应用程序中使用 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();
}

最佳答案

Have a look, the following code doesn't require human interaction

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')
}

Explanation

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

关于javascript - 自动重定向到扫描的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49067908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com