2

How can I mailto: and navigate to a URL with the same jQuery action? I want to do the following:

<script>
  $(function() {
    $('#foo').click(function() {
      window.location.href = 'mailto:foo@bar.com';
      window.location.href = 'bar.com';
    });
  });
</script>

… but the above only executes the mailto.

dave_d
  • 159
  • 1
  • 9

4 Answers4

3

There may be a better way to do it, but it doesn't seem like it without opening up a new window. The method I came up with below works. Tested in Chrome.

jsFiddle: http://jsfiddle.net/Xxv6E/

<script>
  $(function() {
    $('#foo').click(function(e) {
      window.location.href = 'mailto:foo@bar.com';
      setTimeout(function(){
          window.location.href = 'bar.com';
      }, 500);
      e.preventDefault();
    });
  });
</script>

Alternatively, you could probably create an IFRAME element on the fly with jQuery and set its src property to your mailto address, however I think the timeout method is simpler.

Gavin
  • 7,544
  • 4
  • 52
  • 72
2

Try using this,

<a href="mailto:mail@domain.com" onclick="window.location.href='np.html'">send</a>

Using timeout function between two calls

function myFunc() {
    location.href = "mailto:test@test.com&body=Hello!";
    setTimeout(function() {
        location.href = "newPage.html";
    }, 500);
}

good luck!

Aamir Shahzad
  • 6,683
  • 8
  • 47
  • 70
0

I would change the first window.location window.open() -- that should open the mailto part in a new window and still allow the current window to change the current location.

JohnKochJR
  • 133
  • 1
  • 10
0

See this answer

$('#demo12').click(function() { 
    alert('1st click event');
    //  Add items to the cart here
});

$('#demo12').click(function() { 
    alert('2nd click event');
    //  Do something else
});
Community
  • 1
  • 1
JasonAizkalns
  • 20,243
  • 8
  • 57
  • 116