如何使用电子邮件中的单个button打开应用程序或打开链接?

我需要实现一个function,可以从电子邮件帐户打开网页或应用程序。

例如:我有一个应用程序,每当我查看任何用户的configuration文件,用户收到一封电子邮件。 该邮件包含一个button“看configuration文件”,该button的function是每当button被点击,它应该打开一个移动友好的网站。

现在,我的客户端要求,如果应用程序已经安装,然后点击button应打开相关的应用程序,它应该导航到configuration文件。

另外,如果用户在桌面上打开他的电子邮件,则应点击button打开网站。

在移动端,我认为这可以通过URLscheme来完成,但是如何将相同的button关联到2个不同的function。

Instagram已经在做。

请帮忙!

我想出了一个简单的解决scheme,但它需要你的服务器的帮助, – 在你的服务器中添加一个以下的html文件(更新与您的应用程序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/这是你&#x7684;html file url 。你发送的电子邮件将是一个HTML页面的权利,所以当点击查看configuration文件命中上面的url。
  • 以上的HTML代码是直接的,它检查用户是否来自iPhone,iPad或iPod,如果它试图打开你的应用程序urlscheme如果可用,否则将打开Appstore。
  • 如果它不是一个iPhone会打开你的网站。
  • 我已经testing过上面的方法,它工作正常,试试看。