Javascript/jQuery: programmatically follow a link
- by Dan
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).