Open custom_url in new tab

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Open custom_url in new tab

This topic contains 4 replies, has 2 voices, and was last updated by Alex Dowding alexdowding 8 years, 6 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6150
    Alex Dowding
    alexdowding
    Participant

    Apologies if this comes under customisation. I would like to be able to set target _blank for all instances of the custom_url. We have some pages on our site (production atm) that we would like to open straight into another website. We are building a advice database containing in house data and links to external sources.

    I found the thread about changing the js file so that all links open in _blank but I need to restrict this just to custom_url function. Is this a quick fix in the js or the php function?

    Implemented this way, custom_url script could be used by anyone wanting to open specific links in _blank as well so could be cool new feature if it is possible.

    #6155
    Ernest Marcinko
    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 :)


    #6175
    Alex Dowding
    alexdowding
    Participant

    Hi Ernest,

    Thank you for the quick reply. Where do I need to place the javascript? In the header or create a file and call it?

    Sorry, I’m not a coder yet, but starting out……

    Thank you for the solution,

    Alex

    #6177
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    I rather suggest using the footer, just before the closing body tag. It’s usually the best place for inline scripts. Don’t forget to put the code inbetween script tags.

    Best,
    Ernest Marcinko

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


    #6182
    Alex Dowding
    alexdowding
    Participant

    Brilliant. Works like a charm.

    Thank you so much 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Open custom_url in new tab’ is closed to new replies.