Find out if HTC phone enters a mobile app - javascript

I know that this code will redirect for blackberries;
if ((/blackberry/i.test(navigator.userAgent))) {
//Send to mobile page (Blackberries)
window.location = ("../Default.aspx");
}
But what would I use to replace blackberry for HTC phones?
I looked here but there seems to be different ones for just about every phone. Is there a single call that I could use?
Edit A C# way to detect would work too. Something along the lines of this:
if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true"){
if(Request.Browser ["BlackBerry"] == "true")
{
if(int.Parse(Request.Browser.Version) < 4.5)
{
//This is how you get blackberry version right?
}
}
else if(Request.UserAgent.ToUpper().Contains("HTC"))
{
}
}

To find if a phone is an HTC server side do this:
if(Request.UserAgent.ToUpper().Contains("HTC")){
//Code
}

Related

Call XRSystem.isSessionSupported return true, but Failed to execute 'requestSession' on 'XRSystem'

I'm trying to make a webXR application with A-Frame.
I want to detect whether user device(usally mobile) is support AR or not,
So I follow this instruction.
navigator.xr.isSessionSupported("immersive-ar").then((allow) => {
if (allow === false) {
message.innerHTML = `AR not supported`;
}
});
if (navigator.xr === undefined) {
message.innerHTML = `XR not supported`;
}
The problem is that Even the paramter allow is return true, but when user touch the button at bottom right(Enter AR), It's throw an error of Could not create a session because: The runtime for this configuration could not be installed.
I can run my application on some mobile, but when the device not support, It will stuck.
Am I wrong? Is there another way to detect supported status?
navigator.xr.isSessionSupported("immersive-ar").then((allow) => {
if (allow === false) {
// Expect: When EnterAR(true) wont working, show this.
message.innerHTML = `AR not supported`;
}
});
if (navigator.xr === undefined) {
// Expect: When EnterAR(true) wont working, or show this.
message.innerHTML = `XR not supported`;
}
Looks like this issue. a-frame uses navigator.xr.supportsSession('immersive-ar') for support detection, but since you have the option to press the AR button, the browser is providing invalid info.
Since the detection can be faulty, You could
get the device info with a library like platform.js
run it against the the ARCore supported devices (there is a .csv available) and check if there is a match

Detect use of mobile phone by JavaScript

I have a web page. When I running the web page on my mobile phone, in that web page, the usage of mobile phone should be identified. If someone touch the display or use the phone in any way, the page should say that you used your phone.
I used JQuery blur focus method to check whether the browser tab is active or inactive. At anytime I use the phone, the tab will be gone to the background and detect that I used it but, Same thing happens for incoming calls. I need a way to prove that I didn't use the phone and it was an incoming call. So basically I need a way to keep someone away from the mobile phone for a certain time and notify if the person used the phone if he used it.
Anyone can help?
Can't take credit for this, I've seen it somewhere before.
function mobileCheck() {
try {
document.createEvent("TouchEvent");
return true;
}
catch(e) { return false; }
}
if (mobileCheck()) {
alert('mobile');
} else {
alert('not mobile');
}
So this is not JQuery but it does get the job done. Uses regexp for this.
let mobile = navigator.appVersion;
var testForMobile = /Mobile|mini|Fennec|Android|iP(ad|od|hone)/.test(mobile);
document.write(testForMobile)
Mobile can be detected by this simple one liner.
var isMobile = navigator.userAgent.match(/(mobi)/i) ? true : false;
isMobile would return true for mobile devices.

Why isnt window.location.href= not forwarding to page using Safari?

My site lets users login via the Fb button, I'm using the FB / Parse.com JDK for this https://parse.com/docs/js/guide#users-facebook-users
Once the user has been identified, the below code logs the user in and forwards them onto a url. This works as expected under Chrome, but will not work using Safari, the page just stays on the fb.html page which is blank
I've seen that there were some historic issues with
window.location.href=
But, can't find a fix that works for my solution. Does anyone know a way around this?
Parse.FacebookUtils.logIn(null, {
success: function(user) {
if (!user.existed()) {
} else {
window.location.href="user_home.html";
}
},
error: function(user, error) {
}
});
Best way work in all browsers:
setTimeout(function(){document.location.href = "user_home.html";},250);
I had this happening to me as well on safari and found this post but found another solution I wanted to add with lots of browser support. Instead of replacing the current location use the method that is on the location object called assign()
document.location.assign(document.location.origin + "/user_home.html")
This also works
location.assign(location.origin + "/user_home.html")
Tested in Chrome and safari on desktop and mobile iOS devices
reference:
https://www.w3schools.com/jsref/met_loc_assign.asp
I think you need to use...
window.location = 'user_home.html';
When I stack to this problem, I made function what working well on any Safari and also all browsers including mobile browsers:
function windowLocation(url){
var X = setTimeout(function(){
window.location.replace(url);
return true;
},300);
if( window.location = url ){
clearTimeout(X);
return true;
} else {
if( window.location.href = url ){
clearTimeout(X);
return true;
}else{
clearTimeout(X);
window.location.replace(url);
return true;
}
}
return false;
};
Is a bit "dirty" solution but give you ability to redirect your page in any case.
Probably because you are doing something before it. In other words, the first step in your click event handler must be window.location.href = "https://example.com";.
I wanted to detect home page but faced same problems for iphone and safari.
I simply added a class called "home" in landing page then just check this class as
if (document.querySelector('.home') !== null) {
// the conditions comes here
}
Details in http://toihid.com/how-to-detect-home-page-in-iphone-and-safari/

Multiple javascript functions on an index page

I am trying to update some existing javascript code in place that navigates the user to a desktop depending on whether their device has Flash or not. However, I now want the option to navigate the user to a Mobile site if the screen width is smaller that 800px.
I have included the code below which is not working and I think I have the characters wrong between the two function requirements. Any guidance would be appreciated.
<script type="text/javascript">
if (screen.width <= 800) {
window.location = "mobile.htm";
}
if ((navigator.appName == "Microsoft Internet Explorer" &&
navigator.appVersion.indexOf("Mac") == -1 &&
navigator.appVersion.indexOf("3.1") == -1) ||
(navigator.plugins && navigator.plugins["Shockwave Flash"])
|| navigator.plugins["Shockwave Flash 2.0"]){
window.location='home_f.htm';
}
else {
window.location='home_n.htm';
}
</script>
I think what is happening is that the code above (with the screen.width and all) is executing properly, but then, while mobile.htm is still loading, the code continues. Because you have Flash, the code below it still executes and before mobile.htm can fully load the browser instead decides to obey the later if statement and go to home_f.htm .
Try creating a function that returns after the first bit, like so:
function redirect() {
if (screen.width <= 800) {
window.location = "mobile.htm";
return;
}
if ((navigator.appName == "Microsoft Internet Explorer" &&
navigator.appVersion.indexOf("Mac") == -1 &&
navigator.appVersion.indexOf("3.1") == -1) ||
(navigator.plugins && navigator.plugins["Shockwave Flash"])
|| navigator.plugins["Shockwave Flash 2.0"]){
window.location='home_f.htm';
}
else {
window.location='home_n.htm';
}
}
redirect();
I'd also like to note that screen.width measures the screen resolution, but if the browser is resized, it will not take into account the browser's new size. It'll take the size of the entire monitor regardless of the size of the browser. If that isn't what you want, read up on measuring the browser width and height here: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
Finally, for what you're doing, that is, detecting mobile devices, you may prefer browser detection to basing it off the screen size. There is a simple way to detect if your user is using Android via a user agent. In your case scenario feature detection is probably not applicable. But do remember to provide a link to the mobile version of the site from your non-mobile version just in case of false positives! You never know.
if(navigator.userAgent.toLowerCase().indexOf("android")!=-1||navigator.userAgent.toLowerCase().indexOf("googletv")!=-1||navigator.userAgent.toLowerCase().indexOf("htc_flyer")!=-1) {
// this person is using Android. Redirect the the mobile site!
window.location = "mobile.htm";
return;
}

mobile site redirect with full site link

I'm using the javascript version from http://detectmobilebrowsers.com/ to redirect to a mobile site. The only thing is that I have a link to go to the full site in the off chance that users want/need to go there.
However, when you click on the link to view the full site from the mobile, it picks back up on the redirection and kicks it back to the mobile version and not to the full site.
I was doing some searching and was wondering if it could be possible to hack it so that it uses
window.location.href.indexOf
or somthing of that nature like this:
if(window.location.href.indexOf("mobile/index.html") > -1)
{window.location = "http://thefullsiteURL.com"}
else { function (a, b) {
if (//mobile direction stuff from detectmobilebrowsers.com
})(navigator.userAgent || navigator.vendor || window.opera,
'http://thefullsiteURL.com/mobile/index.html')};
Keep in mid that this is something that I pieced together and my JS skills are fairly new, so if any one has a more elegant solution I am all for it.
Set a session cookie in conjunction with a querystring value in your full site link. Then, have your mobile detect code check first for the cookie value, second for the query string, and last for user agent mobile detect.
So your full site link should be something like with the query string trigger:
<a href='http://mysite.com?fullsite=true'>Link to full site</a>
And then in your mobile detect:
;(function(a,b) {
if (document.cookie.indexOf('fullsite') > -1) {
return; // skip redirect
}
if (location.search.indexOf('fullsite') > -1) {
document.cookie = 'fullsite=true; path=/;'
return; // skip redirect
}
if (/mobile regex conditional goes here/) {
window.location = b;
}
})(navigator.userAgent || navigator.vendor || window.opera, 'http://thefullsiteURL.com/mobile/index.html')

Categories

Resources