I have an error with the iAd browser that does not allow YouTube videos to play. Apple’s workaround is to implement a javascript call on all YouTube-link button taps that launch the link in the Safari web browser instead of the in-app browser using window.location in the JS.
Code implemented:
window.location = "http://…";
But still not launching in the Safari web browser.
Main Code:
this.onViewActivate = function (event) {
window.location = "https://www.youtube.com/watch?v=eM8Wpq-oD5o&index=3&list=PLbh4x6U6o9F6sLbGWaAtgdvEmceJLYgwO";
};
You code should be using this process:
document.location = 'http://...
because the iAd producer is within a UIWebView. this will prompt to user and let them know they are about to quit the application.
Related
Some pages in my site have a PWA install feature (that are not supported by instagram in-app browser). So when my visitor click in theses pages links I wanna open it in native browser, instead keeping navigation within Instagram in-app browser.
I tried the following:
$('.my-link').on('click', function(evt){
if(navigator.userAgent.includes("Instagram")){
evt.preventDefault();
window.open($(this).attr('href'), '_blank');
return false;
}
return true;
});
The if condition matchs true, but the target pages remains opening in Instagram in-app browser. I have tried window.open($(this).attr('href'), '_system'); also, with no success.
Any clue?
Update 1
Tried to use URIs schemes to force browser opening, but unfortunately it doest seem to be a good solution. Safari doesnt have an URI scheme. Google Chrome does, but we cant garantee user has Chrome Browser in Android and we cant detect what browser user has.
$('a.new-window-if-instagram').on('click', function(evt){
if(navigator.userAgent.includes("Instagram")){
if (/android/i.test(navigator.userAgent)) {
evt.preventDefault();
var url = $(this).attr('href').replace("https://", "googlechromes://");
url = url.replace("http://", "googlechrome://");
window.open(url, '_blank');
return false;
}
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
// Safari doest have URI scheme...
}
}
return true;
});
I'm currently having the same issue, but at least I found a working solution for Android. I don't know if you are using PHP as your back-end language, but if other people find this, this might be useful:
<?php
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if ((strpos($ua, 'mobile/') !== false) && (strpos($ua, 'safari/') == false)) // Validation code for iOS mobile
{
// Show a message that ask user to open with default browser
}
else if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) // Validation code for Android mobile
{
header('Content-type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
}
This is a validation for iOS in-app browsers and Android in-app browsers.
For Android: We change the content type of the page to PDF. Since the in-app browser can't handle PDF files, it will open the page in a real browser (the default one defined in the user's settings). When the page will load again, the validation will fail since it's not an in-app browser again.
For iOS: Since we can validate the in-app browser in iOS but can't redirect the user automaticly, what I'm doing for the moment is showing a message that ask the user to open this page with his default browser (you can change the message with a switch case on the User-Agent since it's not the same step for every in-app browser)
If I ever find a working solution for iOS, I will update my answer.
I have a Dynamics CRM 2016 Online installation. I have created a web resource in this application. This web resource is launched from a button in the account list.
On the desktop this works perfectly, it launches a new window and I can do what I need and then navigate to a new record in crm with
Xrm.Utility.openEntityForm(entity, entityId);
and then close the window with
window.close();
I can also access this webbresource in the (iOS) phone app. But neither of the above two commands work when the resource has loaded.
I can't navigate from the webresource to a record using any of these commands:
Xrm.Utility.openEntityForm(entity, entityId); // throws undefined error
window.open(recordURL); // does nothing
window.location.href = recordURL; // does nothing
And I cannot close the webresource with either of these:
window.close(); // does nothing
window.history.go(-1); // goes to a blank page (even more infuriating).
Are there some specific javascript commands for these things (navigate to record, or go back)? I can't seem to find any references to what commands I should be using in the dynamics 365 app.
This Microsoft documentation site has some information about mobile devices:
"Additionally, Dynamics 365 for phones does not support web
resources and IFRAMES so the client APIs for these controls won't
work. Client APIs for web resources and IFRAMES are supported on
Dynamics 365 for tablets though."
"Dynamics 365 mobile clients also do not support the window.open
method. If you are looking to open an entity form for a new or
existing record, use Xrm.Utility.openEntityForm instead."
So the window functions are not supported. Xrm.Utility.openEntityForm() should work though. Maybe a web API request doesn't deliver a required guid for the function call due to a bad internet connection on mobile devices.
Maybe it's just not supported as well, but nowhere documented. Atleast a very similar function Xrm.Utility.openWebResource() is not supported as state here: Xrm.Utility.openWebresource()
Keep in mind that you have to use parent.Xrm to access the Xrm object inside of webpages that are embedded as an iframe inside a entity form. That counts for webpages opened by window.open() too.
In case it will just not work you could still do some kind of conditional behavior or fallback:
var isCrmForMobile = (Xrm.Page.context.client.getClient() == "Mobile")
if (isCrmForMobile)
{
// Code for CRM for phones and tablets only goes here.
}
else
{
// Code for web browser or CRM for Outlook only goes here.
}
if (Xrm.Page.context.client.getClient() == "Mobile" && Xrm.Page.context.client.getFormFactor() == 3)
{
// Add code that should only run in CRM for phones here
}
// Code for any client goes here.
Objective : A button in iOS native app when clicked opens a url (webpage) in native browser (safari or other, not UiWebView as it no longer supports html file control api) then, using javascript in the opened webpage, close that browser window so revealing the app again.
Opening the URL from the native app is not an issue: How to launch safari and open URL from iOS app?
Closing that resultant browser window is an issue, is there a way to accomplish this?
Launching Your Own Application via a Custom URL Scheme and Pass Parameters.
Here is a nice tutorial on Using Custom URL Scheme in iOS
As in the tutorial, you should parse the URL parameters and store them to use in the app in this method:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(#"Calling Application Bundle ID: %#", sourceApplication);
NSLog(#"URL scheme:%#", [url scheme]);
NSLog(#"URL query: %#", [url query]);
return YES;
}
I have a requirement to show a pdf in inappbrowser when user clicks on a link. It is working fine in ios but not working on android. I am using IBM worklight for my project. Below is the code I have used:
window.open("pdfURL","_blank","location=yes");
In ios the inappbrowser launches and displays the pdf but in android the inappbrowser is launches but no content is displayed
Unlike iOS, which has a built-in PDF viewer - Android's webview does not have PDF viewer built-in.
This is why it is going to fail in Android.
You have 2 choices in Android:
View the file using Google Docs by storing the file at a remote server and redirecting the user like so: window.open(encodeURI('https://docs.google.com/gview?embedded=true&url=http://www.your-server.com/files/your_file.pdf'), '_blank', 'location=yes,EnableViewPortScale=yes');
Or use a Cordova plug-in. For example this one (you can search in Google for more). For this, you'll need to learn how to create Cordova plug-ins in Worklight.
You can read more options here: Phonegap InAppBrowser display pdf 2.7.0
Try using
window.open('pdfURL',"_system","location=yes,enableViewportScale=yes,hidden=no");
where using _system will download the file and open it in the system's application like Chrome or other PDF viewers.
Use uriEncodeComponent(link) and https://docs.google.com/viewer?url= link
Doc, Excel, Powerpoint and pdf all supported.
Use the cordova in app browser.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.open = cordova.InAppBrowser.open;
}
$("body").on("click",function(e){
var clicked = $(e.target);
if(clicked.is('a, a *'))
{
clicked = clicked.closest("a");
var link = clicked.attr("href");
if(link.indexOf("https://") !== -1)
{
if(true) //use to be able to determine browser from app
{
link = "http://docs.google.com/viewer?url=" + encodeURIComponent(link) + "&embedded=true";
}
window.open(link, "_blank", "location=no,toolbar=no,hardwareback=yes");
return false;
}
}
});
Using google drive viewer seems like a good quick option.
But moving forward they may change or depreciate their API and you will have to find a new way to support this.
Also security is another consideration here as your file is publicly available and downloadable.
I had a similar situation in a recent project and we solved it by using: pdf.js
This is a JS based PDF parser with a good set of reader functionalities.. its not as smooth as a native one but did the job for us.
It's main advantage is that we had the control over the codes and were able to open files from the device file system.
If you want to go for a more native like in-app route, then as #Idan Adar mentioned a native library + cordova plugin is the way to go.
Try this code it's working fine for me.
var inAppBrowserRef;
var target = "_system";
var options = "location=yes,hidden=no,enableViewportScale=yes,toolbar=no,hardwareback=yes";
inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
It's working for me
window.open(link, "_blank","location=yes");
Here is the situation:
I have a web page that needs to check through JavaScript if my app is already installed on the android device it is currently running on.
If the app is installed the page will show a link (with custom protocol) to launch the app,
otherwise the page should show a link to the android market.
I can manage the links to app and to market. The only remaining step is to detect the presence of the app on the device from within JavaScript code (or perhaps try to catch a possible error of unsupported protocol as an indication of not existing app).
When I
click on a web link with
my custom app protocol and
the app is not yet installed on the device
I can see that the android environment generates an "protocol is not supported" type error.
Unfortunately, I am not able to capture that error in the JavaScript code to divert the user to the android market.
I guess both direct detection and error detection are valid methods if they exist at all.
Any ideas how can I accomplish that?
Thanks for help.
Don't use a custom protocol.
Instead, set up your <intent-filter> to watch for a well-known URL (e.g., set the scheme, host, and path). That URL should point to the page where your "download the app" instructions lie.
Then, if the user clicks the link to the well-known URL from someplace else, it will launch your app if installed, or will bring up your Web page if not.
I also had the same question, but I solve it like this:
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
if(isAndroid) { // if is android
// your app address for local
var ifrSrc = 'intent://example.com#Intent;scheme=my_scheme;action=android.intent.action.VIEW;end';
var ifr = document.createElement('iframe');
ifr.src = ifrSrc ;
ifr.onload = function() { // if app is not installed, then will go this function
window.location = 'http://your.app_download_page.com';
};
ifr.style.display = 'none';
document.body.appendChild(ifr);
setTimeout(function(){
document.body.removeChild(ifr); // remove the iframe element
}, 1000);
} else { // if is not android
window.location = 'http://google.com';
}
Hope this can help someone may has this problem.
You can use an iframe which src url is the custom protocol of your app while at the same time you can display your webpage if the custom protocol is not handled. You can also set the iframe to invisble using frameborder="0" and width and height = 0;