Skip to content

Instantly share code, notes, and snippets.

@ambar
Created April 25, 2013 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambar/5459238 to your computer and use it in GitHub Desktop.
Save ambar/5459238 to your computer and use it in GitHub Desktop.
OpenInApp, from instagram
var exports = //
exports.protocal = 'zhihu://'
exports.applink = 'http://itunes.apple.com/cn/app/id432274380'
/**
* 尝试在 zhihu iPhone App 中打开链接
* @param {string} url
*/
exports.open = function(url) {
var redirect = false
if (url.indexOf(exports.protocal) === -1) {
url = exports.protocal + url
}
window.location = url
window.setTimeout(function() {
redirect = true
window.location = exports.applink
}, 250)
window.setTimeout(function() {
if (redirect) {
window.location.reload()
}
}, 500)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment