Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

android - Cordova opening a web page in device browser

Ok i have a problem.Currently i have edited my CordovaWebView.java class so that when i press the device back button,the application will be asked to close.

 public boolean backHistory() {
        // Check webview first to see if there is a history
        // This is needed to support curPage#diffLink, since they are added to appView's history, but not our history url array (JQMobile behavior)
        if (super.canGoBack()) {

            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            builder.setTitle("Sign out Confirm")
                    .setMessage("Are you sure you want to logout?")
                    .setCancelable(false)
                    .setPositiveButton("Ok",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {

                                    cordova.getActivity().finish();
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int id) {
                                    dialog.cancel();
                                }
                            }).show();

           // super.goBack();
            return true;
        }

        return false;
    }

So when i'm opening a new web page from my application it just opens the web page inside my application itself. So i dont have a way to go back after i go to my web page because the application will be asked to close because of the edits i have done.

Is there a way to open a web page in device browser OR can i make a additional edit to go back when a web page is opened.

i tried these methods to open in device brower but did not work.

var url = $state.href('myroute', {parameter: "parameter"});
window.open("https://www.google.lk/",'_system');
window.open('http://www.myurl.nl', '_system', 'location=yes');
navigator.app.loadUrl("http://google.com", {openExternal : true});

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to use inAppBrowser plugin https://github.com/apache/cordova-plugin-inappbrowser

Then you can use this code to open the external browser:

var ref = window.open('http://apache.org', '_system', 'location=yes');

P.S. you don't have to edit CordovaWebView.java to make the back button work, you can do that with javascript http://cordova.apache.org/docs/en/4.0.0/cordova_events_events.md.html#backbutton


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...