Currently, I am in the process of developing a hybrid app using PhoneGap. The main issue I am facing is that when I click on a button on the index page, it should open an external URL. This functionality works perfectly on Android devices but fails on iOS.
I have searched for answers on these specific questions: iOS / Cordova: InAppBrowser not working, cordova/phonegap onclick doesn't work, PhoneGap Build: how to open external url in device browser on Android?, and phonegap open link in browser. Unfortunately, none of these resources provided a solution to my problem.
My first hypothesis is that there could be an error message alerting me of an issue. On the iPhone where I am testing the app, I received this error message:
[ERROR] Error initializing Cordova: Missing Command Error
.
The second possibility is that there might be something wrong with the event handling of the onclick
event within the window.open
method. When I click the open button on the iOS test device, nothing happens.
Below is the code snippet:
document.getElementById("openBrowser").addEventListener("click", function(){
var ref = window.open('http://www.espn.com', '_self', 'location=yes');
ref.addEventListener('loadstart', function(event) { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
ref.addEventListener('loaderror', function(event) { alert('error: ' + event.message); });
ref.addEventListener('exit', function(event) { alert(event.type); });
});
<button id="openBrowser">Open</button>
The above piece of code works as expected and also functions properly on the Google Ripple emulator. Additionally, it works flawlessly on the Android platform. However, I cannot pinpoint whether the issue lies with the former or latter hypothesis mentioned earlier.
In addition, the cordova plugin inappbrowser is included in config.xml
<plugin name="org.apache.cordova.inappbrowser" />
Despite multiple attempts, I have been unable to identify the bug causing this malfunction. I have provided all the necessary information and hope to receive assistance in resolving this seemingly unsolvable problem.
The testing environments include Google Ripple Emulator, Phonegap Desktop App, and the Phonegap Mobile App. The desktop app creates the project directory while the mobile app and Google Ripple emulator connect to the desktop app for testing purposes. Interestingly, the external URL successfully opens on the ripple emulator but encounters errors on the mobile app, displaying an 'initialization error' upon launch.