如何使用电子邮件中的单个按钮打开应用程序或打开链接? [英] How to open app or open link using a single button from email?

查看:396
本文介绍了如何使用电子邮件中的单个按钮打开应用程序或打开链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现一项功能,以便可以从电子邮件帐户打开网页或应用程序.

I need to implement a feature where I can open either a web page or the app from an email account.

例如: 我有一个应用程序,每当我查看任何用户的个人资料时,该用户都会收到一封电子邮件.邮件中包含一个查看个人资料"按钮,只要轻按该按钮,该按钮的功能便会打开一个适合移动设备的网站.

For Example: I have an app in which whenever I view any user's profile, the user receives an email. The mail contains a button "See Profile", the functionality for that button is whenever the button is tapped, it should open a mobile friendly site.

现在,我的客户端要求如果已经安装了该应用程序,则点击该按钮应打开关联的应用程序,并应导航到该配置文件.

Now, my client requires that if the app is already installed, then tapping the button should open the associated app and it should navigate to the profile.

此外,如果用户在桌面上打开电子邮件,则应在点击按钮时打开一个网站.

Also, if the user opens his email on a desktop, then a web site should be opened on tapping the button.

在移动端,我认为可以通过URL方案来完成,但是如何将相同的按钮关联到2种不同的功能.

On mobile side, I think this could be done by URL scheme, but how to associate the same button for 2 different functionalities.

Instagram已经在做.

Instagram is already doing it.

请帮助!

推荐答案

我想出了一个简单的解决方案,但它需要您的服务器帮助, -在服务器中添加以下html文件(使用应用程序urlscheme,itunes link & website url.更新)

I came up with a simple solution but it needs your server help, - Add a following html file in your server (update with your app urlscheme,itunes link & website url.)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="gencyolcu" />
<title>Social Media Share</title>
<script>    
 function openProfile() {
    var userAgent = navigator.userAgent || navigator.vendor || window.opera;
    if( userAgent.match( /iPad/i ) || userAgent.match( /iPhone/i ) || userAgent.match( /iPod/i ) )
    {
        window.location.href = "appurlscheme://;
        setTimeout(function () { 
        window.location = "https://itunes.apple.com/us/app/yourApp/id593274564?ls=1&mt=8";}, 25);
    }
    else
    {
        window.location = "https://www.google.co.in/?gfe_rd=cr&ei=sLSuWM4B7MjwB-6LtagE"
    }
}

</script>
</head>
<body onload="openProfile()"></body>
</html>

  • 让我们假设 http://dev46.com/testfile/这是您的html file url.您发送的电子邮件将是一个html页面,因此,在单击查看个人资料时,请单击上面的URL.
  • 上面的html代码很简单,它会检查用户是否来自 iPhone,iPad或iPod ,以便尝试打开您的应用程序urlscheme(如果可用),否则它将打开Appstore.
  • li>
  • 如果不是iPhone,它将打开您的网站.
  • 我已经通过上述方法测试了它的工作原理,请尝试一下.
    • Let us assume http://dev46.com/testfile/ this is your html file url.Email you are sending will be a html page right, So while clicking See Profile hit the above url.
    • Above html code is straight forward,It checks whether user comes from iPhone,iPad or iPod if it so it tries to open you apps urlscheme if available otherwise it will open Appstore.
    • If it is not an iphone it will open your web site.
    • I had tested above method it's working fine,give it a try.
    • 这篇关于如何使用电子邮件中的单个按钮打开应用程序或打开链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆