How to Return to Local from a Web Page

Asked 1 years ago, Updated 1 years ago, 58 views

I have a question because I didn't understand the document.

If you display a web page in the Monaca app with <a href="URL">, you should open a web page in the app.

Is it possible to return to the local side of index.html from this web page?

After transitioning to the web page, I was able to return when I pressed the physical back button on Android, but what I want to do is to install a button inside the web page and tap it to return to the local file.

If anyone knows, please let me know.

javascript monaca webview

2022-09-30 19:46

1 Answers

Since you use the InAppBrowser plug-in, you must add the InAppBrowser plug-in from the Cordova plug-in management.

If you click the a tag, change the action to run window.open() in _blank.
In the loadstop event of the InAppBrowser, executeScript() sets the [CLOSE] button at the bottom of the page displayed in the browser and opens about:blank.
If the URL contains about:blank, run ref.close() to close the browser.
Web If you click the button on the web side and you have included opening about:blank, you do not need executeScript().

Please refer to the page below as well.
cordova-plugin-inappbrowser

<!DOCTYPE HTML>
<html>
<head>
    <metacharset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scale=no">
    <meta http-equiv="Content-Security-Policy" content="default-src*data:;style-src*'unsafe-inline';script-src*'unsafe-inline'"unsafe-eval'">
    <script src="components/loader.js"></script>
    <link rel="stylesheet" href="components/loader.css">
    <link rel="stylesheet" href="css/style.css">
    <script>
        "use strict";
        window.addEventListener("load", function(e){
console.log("load");
            variable= document.getElementById("jump_url");
            em.addEventListener("click", function(e){
console.log("click");
                var ref=window.open("http://ja.stackoverflow.com/", "_blank", "location=no");
                ref.addEventListener("loadstop", function(e){
console.log("loadstop" + e.url);
                    if(e.url.search(/about:blank/)>-1){
                        ref.close();
                    } else{
                        ref.executeScript({
                            code: "var btn=document.createElement('button'); start=document.createTextNode('CLOSE'); btn.appendChild(t); btn.addEventListener('click', function(e) {window.open('about:blank'); },false.bald.body(appendCold');"
                        });
                    }
                }, false);
                ref.addEventListener("exit", function(e){
console.log("exit");
                    alert("close browser");
                });
            }, false);
        }, false);
    </script>
</head>
<body>
    <br of >
    <aid="jump_url" href="#">StackOverFlow</a>
</body>
</html>


2022-09-30 19:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.