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
2 Answers
Reset to default 2Use 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
版权声明:本文标题:javascript - How to execute a href without redirection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744212881a2595503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论