[ACCEPTED]-How to navigate href in anchor tag via JavaScript-jquery
Accepted answer
You could do:
window.location = $("a").attr("href");
If you want to keep the referrer, you 2 could do this:
var href = $('a').attr('href');
$('<form>').attr({action: href, method: 'GET'}).appendTo($('body')).submit();
It is hackish, but works in 1 all browsers.
document.location.href = "#wanted_Location";
0
Maybe something like this is what you're 1 looking for?
$(document).ready(function () {
$("a").each(function(){
if($(this).click()){
document.location.href = $(this).attr("href");
}
});
});
There is a simpler way to achieve it,
HTML
<a href="https://getbootstrap.com/" id="fooLinkID">Bootstrap is life </a>
JavaScript
// Simulating click after 3 seconds
setTimeout(function(){
document.getElementById('fooLinkID').click();
}, 3 * 1000);
Using 2 plain javascript to simulate a click.
You 1 can check working example here on jsFiddle.
Okay, referer doesn't get set using document.location 4 (as per my other answer), might work with 3 window.navigate(url)? If that doesn't work 2 the following might, though it's quite - ehrm 1 - ugly:
$(function() {
$("a").each(function(){
if($(this).click()){
$('<form method="get" action="' + $(this).attr("href") + '"></form>').appendTo("body").submit();
return false;
}
});
});
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.