Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  21] [ 3]  / answers: 1 / hits: 95412  / 13 Years ago, tue, february 21, 2012, 12:00:00

On clicking a link, it should redirect to the current page. How do I do this with JavaScript?


More From » jquery

 Answers
5

Assuming you mean the link should refresh the current page, you can use window.location.reload(). In jQuery it would look like this:


<a href="#" id="myLink">Refresh current page</a>

$("#myLink").click(function() {
window.location.reload();
});

In plain JS it would look like this:


document.querySelector("#myLink").addEventListener('click', function() {
window.location.reload();
});

[#87316] Monday, February 20, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
stefanicarolinat questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Fri, Apr 16, 21, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;