Created
May 26, 2015 04:32
-
-
Save nloko/19e121853b0c0cd5c483 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/mejiyu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://code.jquery.com/jquery-git.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function isApple() { | |
return /(iPad|iPhone|iPod)/g.test( navigator.userAgent ); | |
} | |
function isAndroid() { | |
return /(android)/i.test(navigator.userAgent); | |
} | |
function loadApp(appUrl) { | |
if (isApple()) { | |
loadAppForiOS(appUrl); | |
} else if (isAndroid()) { | |
loadAppForAndroid(appUrl); | |
} | |
// let the fallback fallback | |
} | |
function loadAppForiOS(appUrl) { | |
$('<iframe />', { | |
name: 'appFrame', | |
id: 'appFrame', | |
src: appUrl | |
}) | |
.css({ | |
display: 'none' | |
}) | |
.appendTo('body'); | |
} | |
function loadAppForAndroid(appUrl) { | |
document.location = appUrl; | |
} | |
function setupFallback(fallbackUrl) { | |
var timeoutId = setTimeout(function() { | |
document.location = fallbackUrl; | |
}, 500); | |
$(window).one('pagehide', function() { | |
clearTimeout(timeoutId); | |
}); | |
} | |
$(function() { | |
setupFallback("http://facebook.com/neil.loknath"); | |
// use maps:// to test installed app in simulator | |
loadApp("mapsx://"); | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function isApple() { | |
return /(iPad|iPhone|iPod)/g.test( navigator.userAgent ); | |
} | |
function isAndroid() { | |
return /(android)/i.test(navigator.userAgent); | |
} | |
function loadApp(appUrl) { | |
if (isApple()) { | |
loadAppForiOS(appUrl); | |
} else if (isAndroid()) { | |
loadAppForAndroid(appUrl); | |
} | |
// let the fallback fallback | |
} | |
function loadAppForiOS(appUrl) { | |
$('<iframe />', { | |
name: 'appFrame', | |
id: 'appFrame', | |
src: appUrl | |
}) | |
.css({ | |
display: 'none' | |
}) | |
.appendTo('body'); | |
} | |
function loadAppForAndroid(appUrl) { | |
document.location = appUrl; | |
} | |
function setupFallback(fallbackUrl) { | |
var timeoutId = setTimeout(function() { | |
document.location = fallbackUrl; | |
}, 500); | |
$(window).one('pagehide', function() { | |
clearTimeout(timeoutId); | |
}); | |
} | |
$(function() { | |
setupFallback("http://facebook.com/neil.loknath"); | |
// use maps:// to test installed app in simulator | |
loadApp("mapsx://"); | |
});</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isApple() { | |
return /(iPad|iPhone|iPod)/g.test( navigator.userAgent ); | |
} | |
function isAndroid() { | |
return /(android)/i.test(navigator.userAgent); | |
} | |
function loadApp(appUrl) { | |
if (isApple()) { | |
loadAppForiOS(appUrl); | |
} else if (isAndroid()) { | |
loadAppForAndroid(appUrl); | |
} | |
// let the fallback fallback | |
} | |
function loadAppForiOS(appUrl) { | |
$('<iframe />', { | |
name: 'appFrame', | |
id: 'appFrame', | |
src: appUrl | |
}) | |
.css({ | |
display: 'none' | |
}) | |
.appendTo('body'); | |
} | |
function loadAppForAndroid(appUrl) { | |
document.location = appUrl; | |
} | |
function setupFallback(fallbackUrl) { | |
var timeoutId = setTimeout(function() { | |
document.location = fallbackUrl; | |
}, 500); | |
$(window).one('pagehide', function() { | |
clearTimeout(timeoutId); | |
}); | |
} | |
$(function() { | |
setupFallback("http://facebook.com/neil.loknath"); | |
// use maps:// to test installed app in simulator | |
loadApp("mapsx://"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment