用于重定向的移动电子邮件启动+ onclick事件

时间:2016-10-14 03:47:00

标签: javascript android jquery jquery-mobile mobile

我在手机上有两个简单的文字功能:

  1. 使用预先填充的主题和正文打开电子邮件
  2. onclick将用户重定向到指定网址的功能
  3. 类似的网站是这样的: http://app.mobileoptin.com/c2926/advertlines

    在上面的示例中,在移动浏览器中,如果用户点击“Click Here For Access”按钮,它将:

    1. 打开带有文字的电子邮件移动客户端
    2. 将用户在后台重定向到特定网址
    3. 这正是我所需要的。

      代码我有:

      <!DOCTYPE html>
      <html lang="en">
          <head>
              <meta charset="UTF-8">
              <title>Document</title>
              <script type="text/javascript">
                      function Redirect() {
                       window.location.href="http://www.google.com";   
                  }
              </script>
          </head>
          <body>
              <a href="mailto:test@theearth.com?subject=Circle Around&body=Some blah" name="redirect" onclick="Redirect();">Email</a>
          </body>
      </html>
      

      它在桌面上运行良好,但由于某些原因我无法在移动设备上运行,至少在Android中。

      感谢您的想法,如果有更好的方法,欢迎您的建议。

1 个答案:

答案 0 :(得分:0)

 /// add here your url link
    String url = "http://www.xxxxxxxx.com/apply";

    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append("hi friends please visit my website for");
    int start = builder.length();
    builder.append(url);
    int end = builder.length();

    builder.setSpan(new URLSpan(url), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

      Intent i = new Intent(Intent.ACTION_SEND);
      i.setType("message/rfc822");
      i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"abcd@gmail.com"});
      i.putExtra(Intent.EXTRA_SUBJECT, "subject of email is this");
      i.putExtra(Intent.EXTRA_TEXT, builder);
       try {
        startActivity(Intent.createChooser(i, "Send mail..."));
           } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }