Kondensator Android WebView: Back Blood zeigt leere SeiteAndroid

Forum für diejenigen, die für Android programmieren
Anonymous
 Kondensator Android WebView: Back Blood zeigt leere Seite

Post by Anonymous »

Ich erstelle eine Android -App mit Kondensator, die eine Web -App (eine Website -URL) in einem Webview lädt. Das Drücken der Back -Taste wird schließlich die App schließlich geschlossen. Lassen Sie mich wissen, ob ich etwas falsch mache. Ich habe darüber nachgedacht, es manuell über den Rückknopf zu handhaben, aber das hilft weder < /p>

Code: Select all

App.addListener('backButton', async () => {
console.log('[BACK BUTTON] pressed');
const browser = this.browserRef;

if (!browser) {
console.log('[BACK BUTTON] No browser open → exit app');
App.exitApp();
return;
}

if (browser) {
const current = this.iabHistory[this.iabHistory.length - 1] || '';
console.log('[BACK BUTTON] Current URL in history:', current);
if (!current || current === 'about:blank' || current.includes('/mobile/loader')) {
console.warn('[BACK BUTTON] At loader/blank → closing browser');

browser.close();
this.browserRef = null;
App.exitApp();
return;
}

let idx = this.iabHistory.length - 2;
let prevUrl = '';
while (idx >= 0) {
const candidate = this.iabHistory[idx];
if (candidate && candidate !== current && !candidate.includes('/mobile/loader')) {
prevUrl = candidate;
break;
}
idx--;
}

if (prevUrl) {
console.log('[BACK BUTTON] Navigating back to:', prevUrl);

browser.executeScript({code: `window.location.replace('${prevUrl}');`});
this.iabHistory = this.iabHistory.slice(0, idx + 1);
console.log('[BACK BUTTON] jumped to', prevUrl, 'new stack=', this.iabHistory.slice());
} else {

browser.close();
this.browserRef = null;
App.exitApp();
}

} else {
console.warn('[BACK BUTTON] No previous URL → closing browser');

if (window.history.length > 1) {
window.history.back();
} else {
App.exitApp();
}
}
});
< /code>
und der andere Code für capacitor.config.ts wie unten: < /p>
"@capacitor/android": "^7.4.2",
"@capacitor/app": "7.0.1",
"@capacitor/browser": "^7.0.1",
"@capacitor/camera": "^7.0.1",
"@capacitor/core": "^7.4.2",
"@capacitor/filesystem": "^7.1.4",
"@capacitor/geolocation": "^7.1.4",
< /code>
Und für WebView verwende ich die folgende < /p>
this.browserRef = this.iab.create('https://xxxxxxx.com/mobile', '_blank', {
location: 'no',
zoom: 'no',
hardwareback: 'yes',
mediaPlaybackRequiresUserAction: 'no',
shouldPauseOnSuspend: 'no',
allowInlineMediaPlayback: 'yes',
toolbar: 'no',
clearcache: 'yes',
clearsessioncache: 'yes',
});

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post