Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a href without redirection

I want to execute a href without redirecting me to the page. execution in background. here is my code

    <a id="speechOutputLink" href="http://translate.google.com/translate_tts?tl=fr&q=text" rel="noreferrer" >Download</a>

When i click on the the href Download i don't want to be redirected to the page of google translator. How can i do this?

like image 428
junior developper Avatar asked Aug 13 '26 17:08

junior developper


1 Answers

Use jQuery's event.preventDefault() method:

If this method is called, the default action of the event will not be triggered.

$('a#speechOutputLink').on('click', function(e) {
    e.preventDefault();

    ...
});
like image 66
James Donnelly Avatar answered Aug 15 '26 06:08

James Donnelly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!