Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Davis Rousseau
Davis Rousseau
6,670 Points

Javascript on how to stop all link target=_blank

I need to stop the target="_blank" on all the links

3 Answers

Davis Rousseau
Davis Rousseau
6,670 Points

did not work. Someone else wrote this js.

$(function(){ window.el = { count : 0, clicked : false } var rpSubCat = '.mkt-rp-subcategories' $('.relatedPromo .grid-item').each(function(index){ var relatedPromo = $(this).parents('.relatedPromo') if(index===0){ relatedPromo.addClass('mkt-rp-parentcat') relatedPromo.append($(rpSubCat).css({'top' : -Math.abs($(rpSubCat).outerHeight()+3)})) } var newContent = $(this).find('a').html() $(this).find('a').replaceWith('<div style="cursor:pointer" href="'+$(this).find('a').attr('href')+'">'+newContent+'</div>') $(this).on({ click : function(e){ e.preventDefault(); if(window.el.clicked==true || el.count==0){ window.el.clicked = false; window.el.count++ var subcategories = relatedPromo.children(rpSubCat), gi = subcategories.children('div[grid-item='+(index+1)+']') subcategories.children('.grid-item').hide() if(gi.length===1){ gi.show() $(rpSubCat).css({ 'top' : -Math.abs($(rpSubCat).outerHeight()+3) }) setTimeout(function(){ relatedPromo.find('h2,.product-container-grid').css('visibility','hidden') },400) relatedPromo.animate({ 'height':$(rpSubCat).outerHeight()+5 }) $(rpSubCat).animate({ 'top' : '+='+($(rpSubCat).outerHeight()+5) },function(){ window.el.clicked = true }) }else{ window.location.href = $(this).find('div').attr('href') } } } }) }) $('.mkt-rp-subcategories').each(function(){ $(this).find('.link').on({ click : function(){ window.open($(this).attr('href')) } }) $(this).find('p').on({ click : function(){ window.open($(this).prev().attr('href')) } }) }).append( $('<div/>').attr('class','collapse').append( $('<span/>').attr('class','text').text('Hide / Collapse') ).on({ click : function(){ $('.mkt-rp-parentcat').find('h2,.product-container-grid').css('visibility','visible') $('.mkt-rp-parentcat').animate({ 'height':$('.product-container-grid').outerHeight()+5 }) $(rpSubCat).animate({ 'top' : '-='+($(rpSubCat).outerHeight()+5) }) } }) ) })

Davis Rousseau
Davis Rousseau
6,670 Points

When I click on the link I the main page and a undefined black page it's under this page http://www.medline.com/clinical-solutions/falls-management at the bottom