早上好,我们正在使用应用内浏览器来显示脱机html页面,但是似乎并没有每次都运行我们在页面上设置的执行操作…
任何帮助将不胜感激……我们一直在测试代码,日志记录等以了解其工作原理,但它不想再次执行script…
import { NavController, NavParams, Platform } from 'ionic-angular';
import { InAppBrowser} from "@ionic-native/in-app-browser";
let offlineBowser:any;
let EditInspectionsKey:any = null;
let EditInspections:any = null;
let CurrentPage:any = null;
let BuildingInspectionsKey:any = "inspectionList";
let BuildingInspections:any = null;
let LoggedIn = "false";
export class WebViewPage {
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private platform: Platform,
private iab: InAppBrowser )
{
this.platform.ready().then(() => {
if(BuildingInspections == null && BuildingInspectionsKey != null){
if(localStorage.getItem(BuildingInspectionsKey) != null)
BuildingInspections = localStorage.getItem(BuildingInspectionsKey)
}
/////// LOGIN ///////
if(LoggedIn.includes("true")){
this.openWebpage('https://someWeb.page/Inspections.asp');
}else{
this.openWebpage('https://someWeb.page/login.asp');
}
});
}
openWebpage(passedUrl) {
//################################################################################################
// OFFLINE
//################################################################################################
// const offlineBowser = cordova.InAppBrowser.open("Inspections.html", '_blank', 'location=no,toolbar=no,zoom=no,hidden=true'); // first attempt
// const offlineBowser = this.iab.create("Inspections.html", '_blank', 'location=no,toolbar=no,zoom=no'); // second attempt
offlineBowser = this.iab.create("Inspections.html", '_blank', 'location=no,toolbar=no,zoom=no'); // current attempt
offlineBowser.on('loadstart').subscribe(event => {
if((event.url).includes("Inspections_Edit.html")){
CurrentPage = "Inspections_Edit";
offlineBowser.executeScript({code:this.getOfflineSelectedKeyCI()}).then(function(values3) {
EditInspectionsKey = values3[0];
console.log('values3 is below'); //ONLY EXECUTES THE FIRST TIME
console.log(values3);
});
}
});
offlineBowser.on('loadstop').subscribe(event => {
if((event.url).includes("Inspections_Edit.html")){
CurrentPage = "Inspections_Edit";
offlineBowser.executeScript({code:"document.getElementById('selBCHeading').innerHTML = localStorage.getItem('selectedBuildingName');"});
offlineBowser.executeScript({code:this.getOfflineSelectedKeyCI()}).then(function(values3) {
EditInspectionsKey = values3[0];
console.log('values3 is below'); //THIS NEVER EXECUTES
console.log(values3);
});
}
});
}
private getOfflineSelectedKeyCI(){
return "getOfflineSelectedKeyCI(); function getOfflineSelectedKeyCI(){ var offlineKey = localStorage.getItem('offlineTempSelectedKey'); return offlineKey }";
}
}