Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击在应用浏览器中启动的页面上的按钮时,如何关闭应用浏览器中的phonegap?_Javascript_Cordova_Ibm Mobilefirst - Fatal编程技术网

Javascript 单击在应用浏览器中启动的页面上的按钮时,如何关闭应用浏览器中的phonegap?

Javascript 单击在应用浏览器中启动的页面上的按钮时,如何关闭应用浏览器中的phonegap?,javascript,cordova,ibm-mobilefirst,Javascript,Cordova,Ibm Mobilefirst,在我的混合移动应用程序(为android和ios开发)中,我在应用浏览器中启动sample.html页面,使用下面的代码窗口。打开(“sample.html”,“_blank”,“location=yes”)。这样,它会打开一个inappbrowser窗口,加载sample.html页面,其中的url栏在android中带有“X”标记,在ios中底部带有“Done”按钮。如果我们在android中单击“X”标记或在ios中单击“完成”按钮,它将关闭iApp浏览器。现在,我希望在sample.ht

在我的混合移动应用程序(为android和ios开发)中,我在应用浏览器中启动sample.html页面,使用下面的代码
窗口。打开(“sample.html”,“_blank”,“location=yes”)
。这样,它会打开一个inappbrowser窗口,加载sample.html页面,其中的url栏在android中带有“X”标记,在ios中底部带有“Done”按钮。如果我们在android中单击“X”标记或在ios中单击“完成”按钮,它将关闭iApp浏览器。现在,我希望在sample.html中单击按钮时具有相同的行为。我使用过window.close(),但它不起作用


我正在为我的应用程序使用IBM worklight framework。

InApp Browser
是Cordova附带的功能。
您可以阅读有关它的更多信息,包括所有受支持的
事件

没有“从内部”关闭InAppBrowser实例的直接方法,因此需要对其进行处理。
以下是实现这一目标的一种方法:

  • 在sample.html中添加如下“关闭”链接,例如:

    <!-- Point to some non-existing end-point;
         We'll catch the error and use it to close the InAppBrowser. -->
    <a href="/close">Close</a>
    
    var InAppBrowserReference;
    
    function wlCommonInit(){
    
    }
    
    function openInAppBrowser() {
        // Use location=no,toolbar=no in order to hide the supplied 'close' buttons
        // by the InAppBrowser instance.
        InAppBrowserReference = window.open('sample.html', '_blank', 'location=no,toolbar=no');
        InAppBrowserReference.addEventListener('loaderror', closeInAppBrowser);
    }
    
    function closeInAppBrowser(event) {
        if (event.url.match("/close")) {
            InAppBrowserReference.close();
        }
    }
    

  • 在上面的代码段中,从common\index.html调用了
    openInAppBrowser()
    ,以便为简单起见打开InAppBrowser。

    我已经尝试过类似的选项,但它对我不起作用。我认为,当从index.html而不是sample.html执行该事件时,分配给inappbrowser引用变量的所有AddEventListener都将工作。在我的例子中,当单击sample.html页面上的按钮/链接时,必须执行loaderror事件/函数。请让我知道如果我不理解正确。@ USSR778988,见一个示例项目的答案。注意,应用程序是使用最近发布的WorkLoundation基金会6.3(现在称为MauliLe1.1平台基金会)构建的。因此,如果您使用的是旧版本的Worklight,只需将index.html、sample.html和main.js中的代码复制到您自己的项目中即可。当我从您的项目中复制index.html、sample.html和main.js时,效果很好。但我很困惑,我在我的项目中也使用了相同的代码,但它对我不起作用。问题在于jquery.mobile.js和jquery.js。如果我们在sample.html中包含jquery.mobile-1.3.2.js和jquery.js库,并运行应用程序,当单击sample.html页面上的关闭按钮时,会出现加载页面错误的问题。不确定有什么冲突。请告诉我如何解决此问题。谢谢。您不能在该页面中仅使用jquery,它是一个完全不同的文件,没有任何对jquery的引用。您需要查看关于将CSS和js注入到其中打开的文件中的inappbrowser文档。请注意,inappbrowser旨在打开远程内容,而不是本地内容。也许你不应该在你的项目中使用它,而应该以不同的方式处理它。