Hard to say, try this and let me know if it works ! ??
Solution 2 :
The a tag does not work as you are expecting. The a tag is used to encapsulate a link.
What would work for having the effect that you want is to refactor your functions to look like this:
function changeText1(){
var userInput = document.getElementById('userInput').value;
var url = "https://www.google.co.uk/search?q=" + userInput ;
window.open(url, '_blank').focus();
}
Using the open method of window
Solution 3 :
You can follow the examples below: (a, button) tags
document.getElementById('btn').onclick = function () {
window.open('https://www.google.com', "_blank");
}
I am trying to get my code to open a new tab in the browser rather than opening in the same tab, so I added target="_blank" after the href, but this doesn’t work as I don’t think it is being sent.
does anyone know how to fix this code so it works in a new window?
I tried adding target to this bit but, it didn’t work.
<a href="" target="_blank" id=lnk </a> <br>
Comments
Comment posted by Jesse
Your
Comment posted by Ian
Hi i have changed it but no change of behaviour 🙁
Comment posted by window.open()
So what is your goal here? Your code is very confusing. I think you lack fundamental knowledge of HTML and JavaScript. You’re setting the link in the
Comment posted by Jesse
Also, for future reference, “it doesn’t work” is not a good description of behavior. Include what it’s currently doing, what you’re expecting it to do, any input you give it, what the output for said input is, and any error messages you may be encountering. Simply stating “it doesn’t work” wastes the time of everyone because people reading have to figure out what the problem is themselves when you already know it.
Comment posted by Ian
Point 1 clearly i dont have a scooby doo, that is why im here I hope you feel powerful now you have put me down. 2 no error message. nothing no change no error nothing different it just opens the search in the same window . sorry i cant make it more exciting for you. sorry to waste your time im sure it is to valuable to be reading my reply. i came here for a little help. i leave berated and sad sorry
Comment posted by Jesse
This would both open a new tab and change the current tag because
Comment posted by Ian
@MrZakaz Nice thank you. I will put it in and see what it does.
Comment posted by Ian
ok. thank you, i will have a play and see how that works. i have to admit i thought this would be just me putting stuff in the wrong order. but it seems a little more difficult. thank you. gives me something to look at and googe 🙂