Re: [PhoneGap] InAppBrowser doesn't close by window.close()

9,337 views
Skip to first unread message

Shazron

unread,
Jan 11, 2013, 2:50:42 PM1/11/13
to phonegap
You would call ref.close() here of course....


On Fri, Jan 11, 2013 at 2:36 AM, Denis Brighi <denis....@gmail.com> wrote:
Hi all,
first i would like to thank you for the great work you are done with PhoneGap!
Really so useful or us, developer :-D

I would ask you if i'm missing something in a scenario like this:
- I open a new page in a InAppBrowser (phonegap v. 2.3.0) 

var ref = window.open('www.somesite.com/newPage.html', '_self', 'location=no');

- in the target page there is a button like this:
<form>
<input type=button value="Close" onClick="javascript:window.close()" name="button">
</form>

=> The InAppBrowser doesn't close and neither it calls the Listener attached

ref.addEventListener('exit', function(event) { alert('closed') });

Is this a bug? Is there some workaround?

Thank you so much

Denis Brighi


--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

Denis Brighi

unread,
Jan 12, 2013, 4:15:14 AM1/12/13
to phon...@googlegroups.com
Ok, I would call ref.close() in order to close the child browser from the parent browser.

But how can I close the child browser from the child browser itself?

Shazron

unread,
Jan 12, 2013, 10:39:17 AM1/12/13
to phon...@googlegroups.com
Are we talking about the InAppBrowser here? There is a Done button.

Denis Brighi

unread,
Jan 14, 2013, 7:14:25 AM1/14/13
to phon...@googlegroups.com
Yes, 
but i would like that InAppBrowser self close when a certain page is reached...

Shazron

unread,
Jan 14, 2013, 2:29:34 PM1/14/13
to phonegap
You can use events. See http://wiki.apache.org/cordova/InAppBrowser (Example Usage #4) and this was briefly discussed in the blog posts as well.


Denis Brighi

unread,
Jan 15, 2013, 3:42:06 AM1/15/13
to phon...@googlegroups.com
Example #4 explains how to catch events.

Maybe i am misunderstood. I try to explain again:

On the phonegap side: 
var ref = window.open('www.somesite.com/newPage.html', '_self', 'location=no');
ref.addEventListener('exit', function(event) { alert(event.type); } );


On the server side (the www.somesite.com/newPage.html content):
<form>
<input type=button value="Close" onClick="javascript:window.close()" name="button">
</form>


Pushing the closing button on the newPage.html (opened in the InAppBrowser), it didn't close
and neither the 'exit' event is fired.
My final goal is to open a new window in the InAppBrowser that call a series of pages onto the server
and on the final page it automatically close).

Thank you so much!




Il giorno lunedì 14 gennaio 2013 20:29:34 UTC+1, Shazron Abdullah ha scritto:
You can use events. See http://wiki.apache.org/cordova/InAppBrowser (Example Usage #4) and this was briefly discussed in the blog posts as well.

Shazron

unread,
Jan 15, 2013, 2:41:59 PM1/15/13
to phonegap
And again, why are u calling window.close? Here you have a reference to the InAppBrowser, which you assigned to the variable 'ref'. To close it you call ref.close().

Denis Brighi

unread,
Jan 16, 2013, 12:02:51 PM1/16/13
to phon...@googlegroups.com
On the server side (the www.somesite.com/newPage.html content):
<html>
....
<script>
              ref.close();
</script>
</body>
</html>

It doesn't work. I don't think that variable scope from inside and outside InAppBrowser is the same,
and in fact it doesn't work. 

Is it possible to pass some variable to or back from InAppBrowser ?

Shazron

unread,
Jan 16, 2013, 12:44:51 PM1/16/13
to phonegap
Well, of course - PhoneGap commands can only run in the context of the locally loaded pages (security feature).

Denis Brighi

unread,
Jan 17, 2013, 4:05:16 AM1/17/13
to phon...@googlegroups.com
I know...
So there is no way to let a page close by itself!!

Why a page containing a script "window.close()" cannot close the InAppBroswer plugin? Isn't it a bug or a new feature?

Salman FF

unread,
Jan 17, 2013, 6:27:39 AM1/17/13
to phon...@googlegroups.com
One thing you can do is to have the server redirect to a final page like www.somesite.com/closeInAppBrowser.html . Then add a loadstart eventlistener that checks the url and calls ref.close()  if you are on that page.

Denis Brighi

unread,
Jan 17, 2013, 9:39:31 AM1/17/13
to phon...@googlegroups.com
yeah ... this is a good workaround... i'll try it :D

Denis Brighi

unread,
Jan 18, 2013, 11:42:01 AM1/18/13
to phon...@googlegroups.com
function onDeviceReady() {
         
var ref = window.open('http://apache.org', '_blank', 'location=yes');
         ref
.addEventListener('loadstart', function() { alert('start: ' + event.url); });
         ref
.addEventListener('loadstop', function() { alert('stop: ' + event.url); });
         ref
.addEventListener('exit', function() { alert(event.type); });
   
}
There is an error in phonegap 2.3.0 documentation .... in function() { .... } it miss event => function (event) { alert (...

Denis Brighi

unread,
Jan 21, 2013, 10:51:08 AM1/21/13
to phon...@googlegroups.com
Trying this code: 
var ref = window.open('http://apache.org', '_blank', 'location=yes');

         
// close InAppBrowser after 5 seconds
         setTimeout
(function() {
             ref
.close();
         
}, 5000);
It doesn't close...
The console log is like this:

01-21 16:49:13.798: W/CordovaPlugin(8690): Attempted to send a second callback for ID: InAppBrowser270960984
01-21 16:49:13.798: W/CordovaPlugin(8690): Result was: "OK"
01-21 16:49:13.798: W/CordovaPlugin(8690): Attempted to send a second callback for ID: InAppBrowser270960984
01-21 16:49:13.798: W/CordovaPlugin(8690): Result was: ""
01-21 16:49:13.853: W/CordovaPlugin(8690): Attempted to send a second callback for ID: InAppBrowser270960985
01-21 16:49:13.853: W/CordovaPlugin(8690): Result was: "OK"
01-21 16:49:13.853: W/CordovaPlugin(8690): Attempted to send a second callback for ID: InAppBrowser270960985
01-21 16:49:13.853: W/CordovaPlugin(8690): Result was: ""
01-21 16:49:13.868: W/CordovaPlugin(8690): Attempted to send a second callback for ID: InAppBrowser270960985
01-21 16:49:13.868: W/CordovaPlugin(8690): Result was: {"type":"exit"}



Any idea?

Eduard Gómez Coll

unread,
Jan 21, 2013, 11:13:48 AM1/21/13
to phon...@googlegroups.com
It's possible to pass server side variables to client side with the new page opened by the InAppBrowser?

elsigh

unread,
May 8, 2013, 11:25:14 PM5/8/13
to phon...@googlegroups.com
OAuth presents a good reason why the InAppBrowser should close when window.close() runs in it.

This flow works in a normal browser just fine, i.e.

Load page index.html
Click login button which does
var ref = window.open('myserver/login') and also setInterval(function() { if (ref.closed) { alert('SHAZAM we are logged in!!'); } });
myserver/login redirects to Google|Facebook for OAuth which then does a callback to
myserver/callback?token=etc.. which then does a redirect to
myserver/done.html
done.html has <script>window.close();</script> which triggers that check for ref.closed mentioned above.

Sure, I can add these loadstart/loadstop things but now I've got code which doesn't work in a browser. 

So I do think the InAppBrowser ought to handle window.close

Thoughts?

Shazron

unread,
May 13, 2013, 7:30:39 PM5/13/13
to phonegap
which platform is this?


--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
---
You received this message because you are subscribed to the Google Groups "phonegap" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Vineel Sadineni

unread,
May 18, 2015, 2:23:32 AM5/18/15
to phon...@googlegroups.com
I'm working on the same issue,I want to open (facebook,google+,twitter,IMDB links) links using inappbrowser using "_self" for firefox OS[I tried to use iframe,but unfortunately I'm getting framing issue while opening the above links],and I want to close the inappbrowser using var ref = window.open('http://whitelisted-url.com', '_blank');
  ref.close();

But I'm not knowing how to close it,i.e,how do I call ref.close() because the links open over the whole window ,and this does'nt allow me to add a button so that i can call 
$("#click_button").click(function(){
ref.close();
});
Reply all
Reply to author
Forward
0 new messages