admin管理员组

文章数量:1401499

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

    <a id="speechOutputLink" href=";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?

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./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?

Share Improve this question asked Sep 22, 2014 at 14:23 junior developperjunior developper 4482 gold badges19 silver badges41 bronze badges 2
  • 2 What exactly do you want if you don't want to be redirected? Do you need to do some javascript process instead of going to the url or you want it to open in another tab or window? – andrex Commented Sep 22, 2014 at 14:27
  • The href i'm executing redirect me to the google translator audio playin the text in the href. What i want is to get the audio charged without redirecting me to the google translator page – junior developper Commented Sep 22, 2014 at 14:55
Add a ment  | 

2 Answers 2

Reset to default 2

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();

    ...
});

Adding the 'target' tag to your anchor allows you to open the page in the background or in an iframe, etc. The values accepted are

_blank
_parent
_self
_top
framename
<a id="speechOutputLink" href="http://translate.google./translate_tts?tl=fr&q=text" rel="noreferrer" target="_blank">Download</a>

Source: http://www.w3schools./tags/tag_a.asp

Additionally you could use the jquery method event.preventDefault() although i've found this to not always work as expected depending on other javascript tasks running.

本文标签: javascriptHow to execute a href without redirectionStack Overflow