-2

Here is some script I copied to create a mailto link which grabs the browser URL and inserts it into the subject of the email. Its working perfect but every page I go to a Javascript alert box pops up saying:

mailto:address@address.ca?Subject="WHAT EVER IS IN THE BROWSER ADDRESS BAR"

Im rubbish with JS. How do I get the script to work without the alert pop up or even so with a lifespan?

<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>

HERE IS A EXAMPLE PAGE:

http://www.door9.co.uk/bex/his-thoughts/

Andrew John
  • 153
  • 2
  • 3
  • 14

3 Answers3

2

Just remove this line window.alert($('#mailtoLink').attr('href')); // = url; so you're left with:

<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);
});//]]>

</script>
Sean Airey
  • 6,352
  • 1
  • 20
  • 38
1

Just remove the window.alert function call.

https://developer.mozilla.org/en-US/docs/DOM/window.alert

jholloman
  • 1,959
  • 14
  • 16
1

Take out this line; it was clearly for demo purposes only

window.alert($('#mailtoLink').attr('href')); // = url;
Adam Casey
  • 949
  • 2
  • 8
  • 24