Capture click and redirecting is not working
I want to capture any hyperlink click and redirect them to different host name. So far it's not working...not even the alert is showing. Below is my code so far:
- $('a').click(function(e){
- e.preventDefault();
- var href = $(this).attr('href');
- var url_hash = $(href).text().replace("https://mysite.knowledg.com/help/article/link/", "https://devbox.mysite.com/kb/article/");
- alert(url_hash);
- //redirect the link to commonspot page
- if($(this).attr('target') === '_blank')
- {
- window.location.href = url_hash;
- }
- else{
- window.open(url_hash);
- }
- });