从浏览器地址栏复制URL并使用html粘贴到表单中?

时间:2012-03-07 19:40:50

标签: java html forms mailto

我希望创建一个表面上非常基本的在线表单。

目标是创建一个带有提交按钮的mailto表单,在提交时,将当前网址添加到浏览器地址栏并将其粘贴到mailto电子邮件窗口中。

表格本身很简单:

form method="post" action="mailto:address@address.ca">
Report a broken link, please use the submit button below. The URL for the broken link will be included automatically.
<br />
<input type="submit" value="Submit">
</form

越简越好,html / java是首选...建议?

2 个答案:

答案 0 :(得分:1)

我建议您使用javascript的document.URL获取网址,然后根据自己的意愿进行操作。

答案 1 :(得分:1)

试试这个

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'>
</script>
  <script type='text/javascript'>
//<![CDATA[ 
  $(window).load(function(){
  var url = "mailto:address@address.ca?Subject=" + window.location;
  $('#mailtoLink').attr('href', url);
  window.alert($('#mailtoLink').attr('href')); // = url;
  });//]]>  
  </script>
</head>
<body>
  Some Text <a id="mailtoLink" href="mailto:address@address.ca" name="mailtoLink">Send Mail</a>
</body>
</html>