简体   繁体   English

PhoneGap inAppBrowser加载停止事件问题

[英]PhoneGap inAppBrowser loadstop event issue

My page is very simple. 我的页面很简单。
When it's running, only shows one button. 当它运行时,仅显示一个按钮。 When clicking the button, inAppBrowser is opened and a page "1.html" is loaded. 单击该按钮时,将打开inAppBrowser并加载页面“ 1.html”。 There is also a button in 1.html, click it will turn to 2.html. 1.html中还有一个按钮,单击将变为2.html。
My goal: 我的目标:
1. After click the button on 1.html, it will turn to 2.html (done). 1.单击1.html上的按钮后,它将变为2.html(完成)。
2. Every time the url in inAppBrowser is changed, alert the url. 2.每次更改inAppBrowser中的URL时,都要警告该URL。 Here is the code of index.html: 这是index.html的代码:

<!DOCTYPE html>
<html>
  <head>
    <title>InAppBrowser.addEventListener Example</title>
    <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for device API libraries to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // device APIs are available
    //
    function onDeviceReady() {
        $("#btn").click(function(){
            var ref = window.open('1.html', '_blank', 'location=yes');
            ref.addEventListener('loadstop', function(event) { alert('stop: ' + event.url); });
        });
    }

    </script>
  </head>
  <body>
    <button id="btn">click</button>
  </body>
</html>

There is one button on "1.html". “ 1.html”上有一个按钮。 If it is clicked, turn to "2.html". 如果单击,请转到“ 2.html”。 Here is the code of 1.html: 这是1.html的代码:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
    <script type="text/javascript" charset="utf-8">
        $(function(){
            $('#btn').click(function(){
                window.href.location = '2.html';
            });
        });
    </script>
  </head>
  <body>
    <button id="btn">Test</button>
    <div id="msg"></div>
  </body>
</html>

Every time inAppBrowser url is changed. 每次inAppBrowser网址都被更改。 Does this trigger loadstop event? 这会触发loadstop事件吗? If yes, why I can't get it work. 如果是,为什么我无法使它正常工作。 If no, how can I implement this? 如果没有,我该如何实施?

You need to check whether the plugin for inappbrowser is correctly configured in the config.xml. 您需要检查config.xml中是否正确配置了inappbrowser插件。 This can be verified in the online phonegap build section or in the config.xml. 可以在在线phonegap构建部分或config.xml中对此进行验证。

The configuration for android in config.xml is: config.xml中android的配置为:

<gap:plugin name="org.apache.cordova.inappbrowser" />

In 1.html , change the code from window.href.location = '2.html'; 1.html ,从window.href.location = '2.html';更改代码window.href.location = '2.html'; to window.location.href = '2.html'; window.location.href = '2.html'; . Then when you are on 1.html and click the button, it will actually change the URL and alert the new URL. 然后,当您在1.html上并单击按钮时,它将实际上更改URL并警告新URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM