How to check if client uses web view? - javascript

I have a component in my website which used to show a download link, I want to remove this component whenever client visits my website using android web view.
Expected to have a function in js that determines this but couldn't find any

You can try using the navigator.userAgent property to determine whether the client is using android web view.
function checkForWebView() {
const userAgent = navigator.userAgent;
if (userAgent.includes('Android')) {
// The client is using an Android device.
// Check if the user agent string contains the name of a known Android web view.
if (userAgent.includes('Chrome') || userAgent.includes('Firefox') || userAgent.includes('SamsungBrowser')) {
// The client is using a web view.
return true;
} else {
// The client is not using a web view.
return false;
}
} else {
// The client is not using an Android device.
return false;
}
}

Related

How to find the ID / Program name of a phone app application in web form?

What I am doing
I am creating a web form that is being used as a QR code to open an application installed in an android / IOS phone. When the user scans the QR code the phone shall run the web form and the web form will check if the application is installed inside the phone, if the application is installed, the web form will open the application, if not it will open the google play store/app store web page based on which OS system is being used.
My problem
Right now my problem is that I do not know what is the name/id of the application to trigger/open it, the only thing I about the app know is that it is called Rymtime inside the setting and also the home screen. The application's google play store link is at here and here for the app store.
PS. I do not own/create the application and do not have any access to modify its code.
What I have tried
I have tried to put its name directly into the code:
window.location = "Rymtime://";
I have also tried to put the "id" thingy found inside its google play store website "www...id=com.time2clock.wai.timeemployee"
window.location = "com.time2clock.wai.timeemployee://";
My Code
I created my code based on this stack overflow question.
Below is my code:
<body>
...
<button name="data1" type="button" onclick="getOS()">Click</button> //I use button to test out the function
...
</body>
<script type="text/javascript">
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'], //as I do not own an Iphone I use this to test out the IOS part
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (iosPlatforms.indexOf(platform) !== -1) {
ios();
} else if (windowsPlatforms.indexOf(platform) !== -1) {
ios(); //as I do not own an Iphone I use this to test out the IOS part
} else if (/Android/.test(userAgent)) {
android();
}
}
function ios() {
setTimeout(function () { window.location = "https://apps.apple.com/my/app/rymtime/id1447217174"; }, 25);
window.location = "Rymtime://"; //I do not test this part because I do not own an Iphone an I am using window to see if the code is being executed, I only check if the website above is runned
}
function android() {
setTimeout(function () { window.location = "https://play.google.com/store/apps/details?id=com.time2clock.wai.timeemployee"; }, 25);
window.location = "Rymtime://"; //The application is not executed thus it redirect to the play store page.
}
</script>
Btw is the location of an application installed inside a phone the same as the others? Like this:
somefile\somefile\packageName
Or something like this:
Username(differ)\somefile\somefile\packageName
Thanks.
I am not sure what it is for IOS but I found out that I can just add &launch=true at the end of the URL of the application's google play store page to launch the app if it is installed.

Is there any way to only allow a user to enter in a page with mobile browser?

Is there any way to only allow a user to enter in a web page with mobile browser? For example, to block a user that tries to access a web page with a desktop browser. I’m using aws to host my web page, nodejs and vuejs
Since you are using vue
npm i -S vue-mobile-detection
then
<div v-if="$isMobile()">MOBILE</div>
<div v-else>DESKTOP OR TABLET</div>
https://renatello.com/vue-js-detect-mobile/
Another way
function _isMobile(){
// if we want a more complete list use this: http://detectmobilebrowsers.com/
// str.test() is more efficent than str.match()
// remember str.test is case sensitive
var isMobile = (/iphone|ipod|android|ie|blackberry|fennec/).test
(navigator.userAgent.toLowerCase());
return isMobile;
}
if(!isMobile()){
//redirect to google or do something else
window.location.href = "http://www.google.com";
}

Adobe DPS Android Entitlement

We are stuck with an Adobe DPS project. We cant get our DPS android app to do Entitlement for our print subscribers and we were wondering if anyone out there has managed to get this right.
We've used Adobe's tutorial here:
http://www.adobe.com/devnet/digitalpublishingsuite/articles/library-store-combined-template.html, with isEntitlementViewer set to true.
The code asks for a username and password and then via Adobe's API AdobeLibraryAPI.js, it authenticates a user via our own API. the very same code is working 100% in the iPad version of the app.
The file that actually processes the login (called LoginDialog.js) contains the following code within a function called clickHandler (we’ve added a few javascript alerts to try debug the login process)
// Login using the authenticationService.
var transaction = adobeDPS.authenticationService.login($username.val(), $password.val());
alert("1: "+transaction.state ); //returns “1: 0”
transaction.completedSignal.addOnce(function(transaction) {
alert("2: "+transaction.state ); //never returns
var transactionStates = adobeDPS.transactionManager.transactionStates;
if (transaction.state == transactionStates.FAILED) {
$("#login .error").html("Authentication Failed.")
} else if (transaction.state == transactionStates.FINISHED){
this.$el.trigger("loginSuccess");
this.close();
}
alert("3: "+transaction.state ); //never returns
}, this);
alert("4: "+transaction.error ); //never returns
Anyone out there with some DPS/android/Entitlement experience?
Android Entitlement only works after an integrator ID is registered with Adobe, as the android viewers service routes are only configured via the integrator ID.
If you do not have an integrator ID, you need to acquire one from Adobe Support.
Also it is worth mentioning, that in contrary to iOS, Android DPS viewers only support one base Route/URL for Authentication and Entitlements.
For Example whereas in iOS you can have the login been done via the first URL:
https://example.com/api/v1/SignInWithCredentials
The second URL for entitlements can be on a different URL:
http://server2.example.com/v1/api/entitlements
In android both URLs have to be the same, e.g.:
https://example.com/api/v1/SignInWithCredentials and
https://example.com/api/v1/entitlements

LaunchOptions.DesiredRemainingView - Split screen launched app

I am trying to open files in their native application from my app.
Windows.Storage.ApplicationData.current.localFolder.getFileAsync("downloads\\" + fileName).then(
function (file) {
var options = new Windows.System.LauncherOptions();
options.displayApplicationPicker = true;
options.desiredRemainingView = Windows.UI.ViewManagement.ViewSizePreference.useHalf;
Windows.System.Launcher.launchFileAsync(file, options).then(
function (success) {
if (success) {
//File launched
} else {
// File launch failed
}
});
});
I tried using the LauncherOptions.DesiredRemainingView to make sure every launch would have the apps split screen (50/50) and the native apps still open at whatever size they default to. Reader(50%), Photos(70%).
In the Windows Dev Center - Windows Store apps there is a sample for launching that includes the different enumerations of DesiredRemainingView and none of the enumerations worked when I built the downloaded sample.
Are there other options (LauncherOptions) that I need to modify/set?

Javascript mobile redirect not working on android devices

I've made a script which should redirect a mobile user to another domain if the site is directly accessed from a mobile device. However if the user has been referred from that domain, they should stay on the page ("View main site").
The reason it has been done like this instead of a server side language is because I don't have access to the server side files, but they have agreed to put in a javascript include.
This code works fine on ios and windows mobile devices, though not android.
Any ideas?
var referrer = 'http://m.example.com/'; // The referring url
var isMobile={
Android:function(){
return navigator.userAgent.match(/Android/i)
},
BlackBerry:function(){
return navigator.userAgent.match(/BlackBerry/i)
},
iOS:function(){
return navigator.userAgent.match(/iPhone|iPad|iPod/i)
},
Opera:function(){
return navigator.userAgent.match(/Opera Mini/i)
},
Windows:function(){
return navigator.userAgent.match(/IEMobile/i)
},
any:function(){
return(isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows())
}
}
window.onload=function(){
var url=referrer;
if(document.referrer.toString()===url){// If the referrer is the same as the url set the cookie
document.cookie="mobile=1";
}
var coo=new Array();
coo=document.cookie.split(';');
var stay=0;
if(isMobile.any()){
for(i in coo){
var cookie=coo[i].split('=');
if(cookie[0].valueOf()==="mobile"){
stay=1;
}
}
if(stay===0){
window.location=url;// if the cookie hasn't been set redirect to the referring url
}
}
}

Categories

Resources