I have coded few lines of java script code. But I am not sure that it is correct or not.
Few months back I published a desktop version website. but when a user coming through a mobile (like android, iPhone or may be windows phone), I want to redirect a new path. Here is the code:
// JavaScript Document
var uAgent = navigator.userAgent.toLowerCase();
if(uAgent.indexOf("android") > -1 || uAgent.indexOf("iphone") > -1 || uAgent.indexOf("windows phone") > -1) {
window.location = "http://website path will come here.";
}
Is it the correct code?
That will work, but its not a great way to do this for a couple of reasons:
Users with JavaScript disabled will not get redirected
Mobile users (some with slow browsers and tight bandwidth limits) will download your desktop page before being redirected to the mobile site.
A better approach if possible, would be to manage this via the web server configuration ideally without any redirects at all. Alternatively, consider serving the same content to all users and changing the layout with media queries.
If you really need to detect a mobile browser (instead of making a mobile-friendly responsive layout like the Responsive template on Initializr that Just Works on mobile browsers - Google for "mobile first" and "responsive design" for more examples) then take a look at these links:
Detect Mobile Browsers
DetectRight
DeviceAtlas
WURFL - Wireless Universal Resource File
Mobile Device Browser File
There are tons of mobile browsers - not only iPhone, Android and Windows - so if you are going to detect them then you need to do it right. See also the jQuery Mobile, a great mobile framework that will make your life easier.
uAgent.indexOf("android") > -1
Android is not just an operating system for smartphones. It also runs on a lot of tablets which can easily handle the desktop-optimized versions of most websites. A friend of mine just complained that some websites only serve the mobile version to his GalaxyTab, even though the normal version would look well on his 10.1" screen.
You also forgot about blackberry and symbian phones.
Related
The website I'm developing recently uses Bootstrap framework. There is no problem about responsiveness while directly visiting the site.
There is another domain name (domainB) and I'm using URL embed method and it loads the actual site.
While visiting the domainB on a mobile device, the responsiveness doesn't work, it loads the desktop site not the mobile-size one.
So, my question:
How to detect if the site is loaded inside an iframe on a mobile device?
I saw that question and by that method it can be understood if the webpage is being loaded inside an iframe but how to detect if the visitor is on a mobile device?
(I don't have any code control on domainB, the URL embed feature is served by domain name registrar company.)
(There could be some SEO issues about this, I know this.)
You could use the mdetect.js script from MobileESP to check if the page is loaded on a mobile device. The method DetectMobileQuick() seems to do what you want, you can find an example here . As described on the MobileESP page, this approach may not work for older phones, including older BlackBerry, PalmOS, and Windows Mobile devices, that have poor support for Javascript. You may also want to check out this post that describes how you can use bootstrap to determine the size of the device view being used.
How to detect which device view you're on using Twitter Bootstrap API?
Guys I build a website and when i am accessing it from the android browser(Default) A script that is very important on the functionality of my website is not being displayed. But when I am accessing it from the android google chrome browser the script is being displayed as I was expected to see.
My site is responsive, it adapted to the screen of the user.
I am using galaxy note 2 and the android version is 4.3.
I was thinking to build an android application such as a browser that is going to be always fullscreen and locked on my site but i do not what google chrome browser has and making my website as I want it to be.
Any help?
I'm not sure what you mean by Android Browser (default). Is there a Samsung Browser already preinstalled on the phone that isn't Chrome?
My guess, off the top of my head, is that JavaScript is disabled on this other browser. If you were to create your own browser with an Android WebView, JavaScript is disabled by default and must be manually set to true.
A quick Google search for 'Samsung Note JavaScript' doesn't return anything readily apparent, but here are a few different Samsung Models with directions on how to enable JavaScript on their browsers. I would imagine the process is similar for the Note 2.
http://support.t-mobile.com/docs/DOC-6782
http://www.droidista.com/2014/06/enabledisable-javascript-on-samsung.html
http://www.att.com/esupport/article.jsp?sid=KB117209&cv=820#fbid=omMGs_GnNUf
I'm a software developer from Germany and I have a special problem concerning smart phones, websites and security!
My web application - which is optimized for smart phones - allowes it to upload photo files (made by the smart phone camera) up to our webserver.
(I use the regular HTML File Control.)
It works fine!
But now we think about possibilities to delete the uploaded photos on the smart phone - via the web app!
Is there any chance to realize that?
Our users work with Firefox 17.0 for Android.
Maybe Mozilla offers proprietary JavaScript code to get access to the local smart phone devices ... ?
Or is there any possibility to change the local security settings of Firefox Mobile?
If both solutions can't be realized, could I develop a smart phone app (which is locally installed) that deletes the photos on the phone? I'm sure I could!
But then I need a possibility to start the app using my website code.
So I have the same security problem - I think so ... again I need a way to "leave" my website to get access to local devices via JavaScript or something else (to start the installed app on the phone).
Is there anybody who has an idea?
Thanks in advance.
Thomas
I´m using jquerymobile to build a simple mobile app and would like to know, whats the best way one should use to make a index page for non-mobile browsers when visiting the mobile app adress ?
I use index.html for now, and i can access it with any desktop browser, but i would want to restrict it to mobile only, and show a different page for desktop browsers.
Which approuch would be better?
Thank you!
In your index.html page you can include some detection script that detects the type of browser (it may be easier to use a whitelist of mobile devices rather then a blacklist of desktop browsers) and then redirects desktop browsers to something like index_desktop.html.
Sorry if the answer isn't as exact as you would have liked but I generally allow desktop browsers the ability to view my mobile pages (I just make sure there is a "View Desktop Version" link somewhere on the page.
Can someone tell me how I can determine (using JavaScript etc.) what browser is being used to visit my site?
I want to redirect to a different page based on these scenarios:
Wheater the user is browsing using Safari on the iPhone.
Using IE on a desktop
Using IE on a WP7 mobile device.
Thanks.
Check out the Javascript Navigator object:
http://www.w3schools.com/js/js_browser.asp
alert(navigator.userAgent);
This script may help you for more complicated detection:
http://www.quirksmode.org/js/detect.html
You should be handling these redirections server-side though. This is particularly true if you have a mobile version of your site. Most mobile browsers do support Javascript just fine, but there are quirks.
Server-side, you can send a redirect by sending the 302 status code, and the location: header. See http://en.wikipedia.org/wiki/HTTP_location
Edit: Since you say that you need to detect mobile browsers now in your comments, just use this script: http://detectmobilebrowsers.mobi/