使用 InAppBrowser 在 Phonegap 中等效的 window.close [英] window.close equivalent in Phonegap with InAppBrowser

查看:27
本文介绍了使用 InAppBrowser 在 Phonegap 中等效的 window.close的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 window.open("apphelp.html", "_blank", "location=no") 打开一个新页面,然后它向我显示了一个包含我的页面的新窗口.在本页的末尾,我想放置一个关闭按钮",以便用户可以返回到他们来自的地方.我用 window.close() 试过了,但没有用.有什么建议吗?

I open a new page with window.open("apphelp.html", "_blank", "location=no"), and then it shows me a new window with my page. At the end of this page, I would like to put a "close button" so the user can come back to where they came from. I tried that with window.close() but it didn't work. Any suggestions?

推荐答案

我使用了一种解决方法...由于 inAppBrowser 只能使用后退按钮或通过 javascript 关闭.我从服务器端显示一个关闭按钮,它会改变当前的 url 触发,也让事件 'loadstop' 使用 .close() 方法,这样只有子浏览器会被关闭,你的应用程序将保持相同的状态.

I use a workaround... Since the inAppBrowser can be closed only with the back button or trough javascript. I display a close button from serverside that will change the current url firing also the event 'loadstop' letting to use the .close() method, in this way only the child browser will be closed, your app will remain in the same state.

例如我的服务器显示一个带有关闭按钮的网页,如下所示:

For example my server display a webpage with a close button, something like this:

<a href="/mobile/close">Close</a>

在我的客户端 javascript(Phonegap 应用程序)中:

in my client side javascript (the Phonegap app):

var ref = window.open(encodeURI(url), '_blank', options);
ref.addEventListener('loadstop', function(event) {        
    if (event.url.match("mobile/close")) {
        ref.close();
    }
});

这篇关于使用 InAppBrowser 在 Phonegap 中等效的 window.close的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆