我在我的应用程序中使用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();
}
看看,下面的代码不需要人工交互
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')
}
说明
window.location.href = "URL";
如果您将url分配给此变量,浏览器将重定向到同一页面中的url,不会打开新选项卡window.open("URL", "_blank");
使用它在新标签页中打开网址