sandeep chhoker
sandeep chhoker

Reputation: 3

How can I enable communication between ionic app and browser?

I am trying to make an app in ionic that can send message to browser in same device (android or ios) and receive response back from browser. Is it possible?

Upvotes: 0

Views: 1247

Answers (1)

Dexter
Dexter

Reputation: 2472

I am pretty sure that it is not possible to communicate with the native device browser to track which URL the user is visiting. However, using cordova-plugin-inappbrowser you can open a browser window inside your application and track URL changes.

By listening to events, either loadstart or loadstop you can see where the user is and retrieve the URL with something like this:

var browserRef = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');

browserRef.addEventListener('loadstart', function(event) {
  console.log(event.url);
});

You can find more information on this plugin here.

Upvotes: 1

Related Questions