window.close相当于PhoneGap的与InAppBrowser [英] window.close equivalent in Phonegap with InAppBrowser

查看:771
本文介绍了window.close相当于PhoneGap的与InAppBrowser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开与新的一页的window.open(apphelp.html,_blank,位置=无),因此它显示了我一个新的窗口我的网页。在这个页面的最后,我想提出一个关闭按钮,这样用户就可以回过头来他是从哪里来的。我试着用 window.close()的,但没有奏效。任何sugestion?

I open a new page with window.open("apphelp.html", "_blank", "location=no"), so 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 he came from. I tried with window.close() but it didn't work. Any sugestion?

推荐答案

我用一种变通方法... 由于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();
    }
});

这篇关于window.close相当于PhoneGap的与InAppBrowser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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