javascript - Redirecting to app store using window.location -


i have script checks make sure on mobile device, grabs feed list of apps , app store addresses, , calls on function that, depending on type of device is, redirects user correct app page.

var redirectoapppage = function(device, types) {     var url;     if (device === 'android') {         url = types.android;     } else if (device === 'iphone' || device === 'ipod') {         url = types.apple;     } else if (device === 'ipad') {         url = types.apple;     } else if (device === 'blackberry') {         url = types.phone;     }     if (url) {         window.location = url;         return false;     }     return url; }; 

this not working. redirect never happens, , instead executes rest of code on page.

i have tried window.location, window.location.href, window.location.assign(url), , window.location.replace(url), none of them working. ideas why wouldn't work?

i remake function , worked me example:

function redirecttoapppage(device, types) {      var url;     if (device === 'android') {         url = types.android;     } else if (device === 'iphone' || device === 'ipod') {         url = types.apple;     } else if (device === 'ipad') {         url = types.apple;     } else if (device === 'blackberry') {         url = types.phone;     }      if (url) {         window.location.replace(url);     } }  // example var device = 'android'; var types = {     android : "https://www.apple.com/itunes/" }  redirecttoapppage(device, types); 

tried jsfiddle.


Comments