window.close相当于PhoneGap的与InAppBrowserclose、window、InAppBrowser、PhoneGap

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

我打开与新的一页的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();
    }
});
阅读全文

相关推荐

最新文章