Reply To: Open custom_url in new tab

#6155

Ernest Marcinko
Keymaster

Hi!

If I understand correctly, you want to open the only the custom URLs in a new window. Well, there is an option to open all links in a new tab on the Layout Options -> Results behavior panel. (first option)

First of all, enable that option so everything is redirected to a new window.

Then, try using this custom Javascript method:

$(function() {
  $('.results').on('click', '.asp_isotopic_item' , function(e) {
     
     var thisDomain = "offthestreets.co.uk";
     var url = $('.asp_content > h3 > a', this).attr('href');
     
     // If it is a local url, prevent opening a new tab, open directly
     if (url.indexOf(thisDomain) > -1) {
        e.preventDefault();
        e.stopPropagation();
        location.href = url;
     } 
     
     return true;
  });
});

It basically attaches a function to the click event of the result item. Then checks if the item url is local or not. If local, then aborts the default operation (opening to a new tab) and instead it opens to the local window. Not sure how this is going to work, but this is the best idea I can think of, which does not include modifying the plugin code.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)