Typescript 如何覆盖InAppBrowser';谁的网址?
我试图使用onTypescript 如何覆盖InAppBrowser';谁的网址?,typescript,ionic-framework,inappbrowser,Typescript,Ionic Framework,Inappbrowser,我试图使用onloadstart事件覆盖InAppBrowser url,但不幸的是,我不知道我是否遗漏了什么,甚至不知道这是否适用 我试图做的是用字符串连接url,因此当用户单击InAappBrowser窗口中的任何url时,我会用连接的字符串覆盖该url 如果有人曾经尝试过类似的方法,我将非常感谢您的帮助 import { Component } from '@angular/core'; import { InAppBrowser } from '@ionic-native/in-app-
loadstart
事件覆盖InAppBrowser url,但不幸的是,我不知道我是否遗漏了什么,甚至不知道这是否适用
我试图做的是用字符串连接url,因此当用户单击InAappBrowser窗口中的任何url时,我会用连接的字符串覆盖该url
如果有人曾经尝试过类似的方法,我将非常感谢您的帮助
import { Component } from '@angular/core';
import { InAppBrowser } from '@ionic-native/in-app-browser';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
browser: any;
constructor(
public iab: InAppBrowser
) {}
openPage(){
this.browser = this.iab.create('http://example.com','_blank','hidden=no,location=yes');
this.browser.on('loadstart')
.subscribe(
data => data.url = data.url + '?mydata=true'
);
}
}
问题是您正在将位置字符串修改为所需的位置字符串,但没有加载它。需要再次将其加载到浏览器中:
data.url = data.url + '?mydata=true'
希望这有帮助。答案是在loadstart上执行javascript代码,使用appbrowser方法中的
executeScript
覆盖使用我的新url单击的任何url
openPage(){
this.browser = this.iab.create('https://example.com/','_blank','hidden=yes,location=yes,clearcache=yes,clearsessioncache=yes');
this.browser.on('loadstart')
.subscribe(
data => {
if(!data.url.includes('?mydata=true')){
this.browser.executeScript({
code: `window.location.href = '${data.url}' + '?mydata=true';`
});
}
}
);
this.browser.show();
}
你能举个例子吗?