Is there a way to close the in app browser? window.close is only working on iOS device, and it doesn't work in Android. I've tried using window.top.close and window.open("","_self") window.close and none of it is working. I've tried to look for which browser does Viber and Line use internally but they don't have any documentation
You can try this:
var win=window.open( "myurl", "_blank");
win.addEventListener( "loadstop", function(){
var loop = window.setInterval(function(){
win.executeScript({
code: "window.shouldClose"
},
function(values){
if(values[0]){
win.close();
window.clearInterval(loop);
}
}
);
},100);
});
In your called window, simply do this, When you want to close it
window.shouldClose=true
I am adding this just for future references. You can set window.location.href to Viber deep link like viber://pa?chatURI=<URI> to navigate back to chat window. Here is the doc page.
Related
I tried to use a deep link inside an iframe on iOS.
It works well if the app is already installed, but if it is not installed yet it does not do anything.
$(".test-app").click(function () {
window.top.location.href = "myapp://......";
setTimeout(function(){
window.top.location.href = "https://......";
});
})
It looks like the window.top.location.href = "https://......"; does not work.
How to use deep link inside iframe on iOS correctly?
Note: if I do not use it in iframe it works fine.
I have a fun little button on a website I am developing here:
http://dev.lapiazzaonline.com/merrick.php
When you click on the takeout menu button on desktop and chrome inspector iPhone simulator it works great.... with a nice little delay.
Now on iOS, nothing happens. I think it might have to do with the hover state issue, but more think my JS is messed up.
this is the js in the behavior.js file
// cool buttons
(function() {
var removeSuccess;
removeSuccess = function() {
return $('.button').removeClass('success');
};
$(document).ready(function() {
return $('.button').click(function(e) {
e.preventDefault();
var goTo = this.getAttribute("href");
$(this).addClass('success');
setTimeout(removeSuccess, 1500);
setTimeout(function(){
window.open(goTo);
},1500);
});
});
}).call(this);
Any ideas?
Thanks,
-Muhu
Your issue here is the use of window.open. You can read more about this here and other similar issues if you search. Unfortunately, there are multiple reports that jQuery trigger will not work either. So, what I would do is just use something like Modernizr, or if you just want to figure out which browser it is, this is a nice tool, and then when you're on iOS or a browser with similar blocking functionality, run a different function that doesn't prevent the default, and opens the link normally.
I am developing Phonegap application and currently i am using InAppBrowser to display external pages. On some of the external pages I place a close button and i want to close the InAppBrowser itself. because InAppBrowser displays these pages that is why the reference of it is not accessed on itself to close it and Please do not suggest me to use ChildBrowser Plugin.
window.close(); //Not Worked for me
or
iabRef.close(); //Also not Worked for me because iabRef is not accessible on InAppBrowser. It is created on Parent Window
Some of the Android device and iOS device display a Done Button to close it. As well as the iPad also display the Done button. but in Case of Android tablet there is not any kind of button to close it.
UPDATE :-
Here is my full code :-
var iabRef = null;
function iabLoadStart(event) {
}
function iabLoadStop(event) {
}
function iabClose(event) {
iabRef.removeEventListener('loadstart', iabLoadStart);
iabRef.removeEventListener('loadstop', iabLoadStop);
iabRef.removeEventListener('exit', iabClose);
}
function startInAppB() {
var myURL=encodeURI('http://www.domain.com/some_path/mypage.html');
iabRef = window.open(myURL,'_blank', 'location=yes');
iabRef.addEventListener('loadstart', iabLoadStart);
iabRef.addEventListener('loadstop', iabLoadStop);
iabRef.addEventListener('exit', iabClose);
}
This worked for me:
var win=window.open( "myurl", "_blank");
win.addEventListener( "loadstop", function(){
var loop = window.setInterval(function(){
win.executeScript({
code: "window.shouldClose"
},
function(values){
if(values[0]){
win.close();
window.clearInterval(loop);
}
}
);
},100);
});
In your called window, simply do:
window.shouldClose=true
When you want to close it
There's a solution provided in this blog post:
cross window communication with cordova's inappbrowser
Essentially, you could use executeScript() from the parent window to the InAppBrowser instance over and over (once or twice a second, for example), to check whether a value in the IAB has been set. Pressing the "close" button in IAB could set such a variable.
When the parent window discovers that the variable has been set in the IAB, the parent window uses the IAB reference to close() it.
There is a SO post here that describes how to do this.
You basically have to get a reference to the inapp browser by calling window.open and hook into the loadstop event. In the loadstop event check to see if the url contains a predefined path (like mobile/close - but could be anything) and then call call close.
Here is the post
https://stackoverflow.com/a/15981972/54805
The title has it all: My page runs in full screen mode (cf. using an icon on the springboard); When I click a link to an external page, I would like to have it open in the normal safari application, not the full screen instance.
How can this be done?
I expected window.open('url', '_blank') to do the trick, but it doesnt.
Thanks!
Edit: code snippet:
$('#gotoWebsitePlaceholder').selectable({
start: function(){
window.open('http://www. ... .com', "_blank");
}
}).hide();
Are you using an anchor tag? My experience is that the default action is to open the href target in the Safari app. I.E., if I didn't cancel the default action via javascript, my app would shift out of the FS app. Can you post a code snippet?
I have discovered that Safari will remain in fullScreen when executing window.open(myURL) or this.location = myURL. However if your url is called using click it will exit fullScreen mode.
I solved with this piece of js (tested in ipad with iOS 5.1.1):
jQuery(document).ready(function ($) {
$('a').click(function() {
if (($(this).attr("target")!="_blank")){
window.location = $(this).attr('href');
return false;
}
});
So only the links with target="_blank" will open in safari.
When I add my 'web app' to my home screen on my iPhone, then open it and click a link, it opens Safari.
I've found a couple of solutions to my question but they don't seem to work:
iPhone Safari Web App opens links in new window
$('a').live('click', function (event)
{
var href = $(this).attr("href");
if (href.indexOf(location.hostname) > -1)
{
event.preventDefault();
window.location = href;
}
});
http://jakeboyles.com/2011/01/16/how-to-build-an-iphone-and-ipad-web-app/
<a ontouchstart="window.location=yourlink.html' ">Your Link</a>
Both of these posts/tutorials were written before iOS5. Is there a new method? Am I doing something wrong?
Appreciate your help
One idea is to make your home screen app an iframe, and making all anchors target it. No javascript needed.
Alternatively:
$('a').on('click touchend', function(ev){
$(this).preventDefault();
window.location = $(this).attr('href');
});
Never use "touchstart" for something like links. You only want to detect when the user stops touching the link. Same thing for detecting key presses, mouse clicks, etc. Its the end of the event you want to detect.
.live has been deprecated in the latest versions of jQuery, so use .on() from now on and it wraps seamlessly around extant and non-extant elements.
This javascript code works for iOS 5 (it worked for me):
In the head tag:
<script type="text/javascript">
function OpenLink(theLink){
window.location.href = theLink.href;
}
</script>
In the link that you want to be opened in the same window:
Link
The code is based on this comment: http://mobile.tutsplus.com/tutorials/iphone/iphone-web-app-meta-tags/comment-page-1/#comment-10699
This worked fine on the iPhone 5
$(document).ready(function(){
// Stop the default behavior of the browser, which
// is to change the URL of the page.
$("a").click(function(event){
event.preventDefault();
// Manually change the location of the page to stay in
// "Standalone" mode and change the URL at the same time.
window.location = $(this).attr('href');
});
});
Remember to link to the newest version of jQuery.
Im the one that wrote the article you are referring to. I still use my javascript method and it works fine for me. The touchstart works fine for web apps as it takes a little longer for the browser to render it. If you are planning on makign a native app then don't use it, but I have used touchstart for many apps and it works fine.
Thanks
Jake Boyles