Mar*_*aer 10 javascript twitter url-scheme
我想使用Twitter应用程序从我的网络应用程序发送推文,而不是在安装推特客户端时使用推特按钮.
如果我在安装了Twitter应用程序的iPhone或Mac上,则在将Web应用程序重定向到"twitter://"URL时会打开此应用程序.(见http://handleopenurl.com/scheme/twitter)
但是,如果我只想在未安装Twitter应用程序的地方显示Twitter按钮,我该如何检查?假设我有这个代码.twitter_app_installed()应该如何?有没有办法检查是否window.location="twitter://...";不起作用?
<div class="twitter-button"><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://google.com" data-text="Hello World">Tweet</a></div>
<div class="twitter-app-button"><a href="twitter://post?message=Hello%20World%20http://google.com">Tweet</a></div>
<script>
function twitter_app_installed() { /* check if window.location="twitter://"; works */}
$(document).ready(function() {
if (twitter_app_installed()) $('.twitter-app-button').show();
else $('.twitter-button').show();
});
</script>
Run Code Online (Sandbox Code Playgroud)
另外:有没有正确的方法将URL添加到twitter://方案?
Jur*_*emo -1
似乎不可能进行此类检查。
我认为(在 iPhone 上)你能做的最好的事情是:
a) 在第一次用户访问时始终显示“下载应用程序”
b) 在按钮单击事件上执行类似的操作:
setTimeout(function () {
window.location = "your store url here";
}, 25);
document.cookie="is_app_installed=true"
window.location = "appname://";
Run Code Online (Sandbox Code Playgroud)
仅当应用程序未安装时才会触发设置的超时
c) 从第二个用户访问开始,可以使用cookie来检查应用程序是否安装。
这个方法有很多不足(如果用户卸载该应用程序或不在itunes上安装它将会失败),但可能是你唯一能做的事情。