Is there a way to force links inside of a defined section to open up in a new window?

(Rob) #1

I will be using a forum plugin and would like to display some of the topics from the forum on different pages via short-codes. The only thing is that once clicked they will open up in the same page. Is there a way to force links to open in a new window?

(Denis B) #2

Make sure that the links are within a div ID eg “blank_div”, use the JS below to add a ‘target’=’_blank’ to ALL the links within that div ID.

  $('#blank_div a').attr('target', '_blank');

(Leland Fiegel) #3

jQuery is probably the easiest way.

If using WordPress, you can also filter the content. See this example: …it seems a little messy though.

I’d personally just use jQuery, @denisb’s code snippet will work fine (assuming you have jQuery included elsewhere on the page).