mailto使用javascript [英] mailto using javascript

查看:91
本文介绍了mailto使用javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户点击图片时使用收件人地址打开一个新的Outlook邮件模板。我已经返回我的代码在HTML页面(与图像链接),每当它加载JavaScript应该打开一个新的邮件模板。但功能不起作用。请让我知道我的代码中有什么问题。

  body onLoad =redirect()

script language =JavaScript

函数重定向()

var email =xyz@something.com
var mailto_link ='mailto:'+ email
window = window.open(mailto_link,'emailWindow')
if(window& window.open&&!window.closed)
window.close()


解决方案

不需要jQuery。而且没有必要打开一个新窗口。协议不会返回HTTP数据到浏览器( mailto: irc:// magnet:, ftp:// (< - 取决于它是如何实现的,通常浏览器内置有FTP客户端) )可以在同一窗口中查询,而不会丢失当前内容。在你的情况下:

pre $ function redirect()
{
window.location.href =mailto: mail@example.org;
}
< body onload =javascript:redirect();>

或者直接

 < body onload =javascript:window.location.href ='mailto:mail@example.org';> 


I want to open a new outlook mail template with the 'To address' whenever a user clicks an image. I have return my code in a html page(linked with the image), whenever it loads the javascript should open a new mail template. But the functionality is not working. Kindly let me know what is wrong in my code.

body onLoad="redirect()"

script language="JavaScript"

function redirect() 

      var email = "xyz@something.com"
      var mailto_link = 'mailto:' + email
      window = window.open(mailto_link, 'emailWindow')
      if (window && window.open && !window.closed)         
          window.close()

解决方案

No need for jQuery. And it isn't necessary to open a new window. Protocols which doesn't return HTTP data to the browser (mailto:, irc://, magnet:, ftp:// (<- it depends how it is implemented, normally the browser has an FTP client built in)) can be queried in the same window without losing the current content. In your case:

function redirect()
{
    window.location.href = "mailto:mail@example.org";
}
<body onload="javascript: redirect();">

Or just directly

<body onload="javascript: window.location.href='mailto:mail@example.org';">

这篇关于mailto使用javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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