i need open vk.com, facebook, twitter apps when user clicks on url, in case app installed.
otherwise, new tab should opened http url.
are there ready solutions this?
i need work @ ios, android & windows devices.
this can done using url scheme. unfortunately, different operating systems (ios, android, etc) respond different url schemes mobile apps. so, first have find out device user using. can obtained making use of navigator.useragent property:
var ua = window.navigator.useragent;
the ua variable string representing user information, such as, browser using. can use string's match method specific values:
var is_ipad = ua.match(/ipad/i) != null, is_iphone = !is_ipad && ((ua.match(/iphone/i) != null) || (ua.match(/ipod/i) != null)), is_ios = is_ipad || is_iphone, is_android = !is_ios && ua.match(/android/i) != null, is_mobile = is_ios || is_android;
now know device user using, can use correct url scheme. android uses intents intent:// prefix , ios uses format appname://parameters. so, can do:
if(is_ios){ window.location = "myapp://view?id=123"; }else if(is_android){ window.location = 'intent://view?id=123#intent;package=my.app.id;scheme=myapp;launchflags=268435456;end;'; }
you may want use timeout ios (android bring play store if app not installed) see if app loaded or not. if app didn't load can set window location standard url.
this solves problem android , ios, however, doesn't cover windows mobile devices. though, i'm sure it's similar approach. haven't found particular libraries abstracts , handles code it's simple implement.
resources / further reading: