dariokomazec Posted January 8, 2022 Share Posted January 8, 2022 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
Agha_Waqas Posted January 8, 2022 Share Posted January 8, 2022 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
dariokomazec Posted January 9, 2022 Author Share Posted January 9, 2022 Hi, I understand that but please check my code above, I want to open "www.google.com" instead of "/search" but in a new tab. With your code it will open "/search" in a new tab and not "google.com" in a new tab... Link to comment
dariokomazec Posted January 9, 2022 Author Share Posted January 9, 2022 <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
tuanphan Posted January 10, 2022 Share Posted January 10, 2022 try this <script> $(document).ready(function() { $('a[href="/search"]').attr('href','https://www.google.com/'); $('a[href="/search"]').attr('target','_blank'); }); </script> Email me if you have need any help (free, of course.). Answer within 24 hours. Or send to forum message Contact Customer Care - Learn CSS - Buy me a coffee (thank you!) Link to comment
Solution dariokomazec Posted January 10, 2022 Author Solution Share Posted January 10, 2022 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
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment