getting current URL of InAppBrowser?

1,222 views
Skip to first unread message

chuh

unread,
Jul 16, 2015, 3:10:43 PM7/16/15
to phon...@googlegroups.com
Is there a way to get the current URL of InAppBrowser which the user is looking at?

I'd like to open external url within my app and have a "bookmark" button where I can save the current URL that the user is viewing. I would like to create a "bookmark/shortcut" page in the app so the user can access their saved pages quickly. 


Jesse Monroy

unread,
Jul 16, 2015, 4:41:18 PM7/16/15
to phon...@googlegroups.com
In theory, it is possible. InAppBrowser is child process and you should be able to see the history. However, saving the URL might be a challenge as the InAppBrowser cannot use phonegap services. Maybe someone else has a better answer.

Jesse

jcesarmobile

unread,
Jul 17, 2015, 4:02:18 AM7/17/15
to phon...@googlegroups.com
You can get the url from javascript on any of the inAppBrowser events (loadstart, loadstop, loaderror, exit)

var ref = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', myCallback);


But for the "bookmark" button, I think you will need to edit the inAppBrowser plugin to add a native button, and as you will use a native button and you will use native code, you can get the url with

webView.getOriginalUrl();



Other way might be to use executeScript and insertCSS to inject javascript and css to create a button inside the page you display


Kerri Shotts

unread,
Jul 18, 2015, 12:28:02 PM7/18/15
to phon...@googlegroups.com, jcesar...@gmail.com
You might also be interested in: https://github.com/initialxy/cordova-plugin-themeablebrowser

You can add additional interface elements and such without having to modify the native code. It's a fork off of the in app browser, IIRC.
Reply all
Reply to author
Forward
0 new messages