Javascript/jQuery: programmatically follow a link

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2012-06-05T23:01:29Z Indexed on 2012/06/06 16:40 UTC
Read the original article Hit count: 361

Filed under:
|
|

In Javascript code, I would like to programmatically cause the browser to follow a link that's on my page. Simple case:

<a id="foo" href="mailto:[email protected]">something</a>

function goToBar() {
   $('#foo').trigger('follow');
}

This is hypothetical as it doesn't actually work. And no, triggering click doesn't do it.

I am aware of window.location and window.open but these differ from native link-following in some ways that matter to me: a) in the presence of a <base /> element, and b) in the case of mailto URLs. The latter in particular is significant. In Firefox at least, calling window.location.href = "mailto:[email protected]" causes the window's unload handlers to fire, whereas simply clicking a mailto link does not, as far as I can tell.

I'm looking for a way to trigger the browser's default handling of links, from Javascript code.

Does such a mechanism exist? Toolkit-specific answers also welcome (especially for Gecko).

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html