0
我注意到,每次在Android應用程序中初始化Worklight/Cordova時,都會調用cordovaInitCallback。特別是,它調用Cordova的「clearHistory」來清除WebView歷史記錄。當我嘗試在多頁面應用程序中使用window.history時,這是一個問題,因爲歷史記錄始終在頁面初始化期間重置。安卓工作燈初始化始終清除WebView歷史記錄
由於該評論暗示此clearHistory調用的目的是爲了防止在直接更新場景中返回到舊頁面,是否可以通過Android環境檢查增強該條件,以便只在直接更新時調用該條件剛剛發生?例如,我可以想到的一種情況是connectOnStartup = false時,不會發生直接更新。
wlclient.js:
var cordovaInitCallback = function(returnedData) {
onEnvInit(options);
if (WL.Client.getEnvironment() == WL.Env.ANDROID) {
if (returnedData !== null && returnedData !== "") {
WL.StaticAppProps.APP_VERSION = returnedData;
}
// In development mode, the application has a settings
// widget in which the user may alter
// the application's root url
// and here the application reads this url, and replaces the
// static prop
// WL.StaticAppProps.WORKLIGHT_ROOT_URL
// __setWLServerAddress for iOS is called within
// wlgap.ios.js's wlCheckReachability
// function because it is an asynchronous call.
// Only in Android we should clear the history of the
// WebView, otherwise when user will
// press the back button after upgrade he will return to the
// html page before the upgrade
if (**WL.Env.ANDROID == getEnv()**) {
cordova.exec(null, null, 'Utils', 'clearHistory', []);
}
}
我目前使用工作燈5.0.5,並已選中此相同的條件5.0.5.1存在。
謝謝!
Worklight是針對單頁應用程序開發的,如果主html頁面上存在太多標記,您應該考慮在主html文件中動態填充html標記。您可以在JavaScript中重寫函數,例如:'console.log = function(){return'hello'}'。現在console.log將只返回'hello'而不是默認行爲。一個選項(我不推薦)是重寫其中一個函數或對象(WL.Env.ANDROID ='hello')。請注意,這是**不是**答案,只是一面評論:)。 – cnandreu 2013-02-28 04:04:01