Jump to content

Redirecting Link with jQuery. Please Help !

Go to solution Solved by dariokomazec,

Recommended Posts

Hi,

I'm not good at coding so any help will be appreciated.

I want to change the default SEARCH link to external one and I have done this successfully with this code below but the problem is I don't know how to force it to open in a new tab. I have tried adding the target= "_blank" to the code but as I already said I'm not good at this so no luck, I don't know how to do this...

<script>
  
  $(document).ready(function() { 
    $('a[href="/search"]').attr('href','https://www.google.com/');
	});
  
</script>

So I need help with this code above, code is 100% working I only want to open the https://www.google.com/ in the new tab...

Thanks

Link to comment
  • Replies 5
  • Views 613
  • Created
  • Last Reply

Top Posters In This Topic

11 hours ago, dariokomazec said:

Hi,

I'm not good at coding so any help will be appreciated.

I want to change the default SEARCH link to external one and I have done this successfully with this code below but the problem is I don't know how to force it to open in a new tab. I have tried adding the target= "_blank" to the code but as I already said I'm not good at this so no luck, I don't know how to do this...

<script>
  
  $(document).ready(function() { 
    $('a[href="/search"]').attr('href','https://www.google.com/');
	});
  
</script>

So I need help with this code above, code is 100% working I only want to open the https://www.google.com/ in the new tab...

Thanks

same thing you need to do via jquery. Add target attr like you add the href.
 

 $('a[href="/search"]').attr("target", "_blank");
Link to comment
<script>
  
  $(document).ready(function() { 
    $('a[href="/search"]').attr('href','https://www.google.com/').attr("target", "_blank");
    });
  
</script>

I don't know is this good to do this this way but it works...? I have added :

.attr("target", "_blank");

to my code and now it opens google.com instead of /search in a new tab...

Link to comment
  • Solution

Not working as needed, it opens up google.com but not in a new tab.

I have figured it out that changing the place works great so this is the final code:

<script>
  $(document).ready(function() { 
    $('a[href="/search"]').attr('target','_blank');
    $('a[href="/search"]').attr('href','https://www.google.com/');
	});
</script>

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.