In my html code I am using an <a>
tag with empty <href>
as the url is not known at the beginning.
Let's say a new aim now is getting known as "www.amazon.de". Now I try to change the href with javascript:
document.getElementById('linkname').setAttribute("href", "www.amazon.de");
But my browser creates only a relative link to my domain like this:
.amazon.de>
(this is shown if i hover over the link)
In my html code I am using an <a>
tag with empty <href>
as the url is not known at the beginning.
Let's say a new aim now is getting known as "www.amazon.de". Now I try to change the href with javascript:
document.getElementById('linkname').setAttribute("href", "www.amazon.de");
But my browser creates only a relative link to my domain like this:
https://www.mydomain.de/www.amazon.de>
(this is shown if i hover over the link)
Share Improve this question edited Mar 8, 2019 at 14:11 Vinz243 9,95611 gold badges45 silver badges95 bronze badges asked Mar 8, 2019 at 14:09 Hubert LohmaierHubert Lohmaier 134 bronze badges3 Answers
Reset to default 8That's because www.amazon.de
is a relative link. To link a different domain (host), you need to begin the authority ponent with double slashes: //www.amazon.de
, or with the scheme included https://www.amazon.de
.
You have to add the protocol ('https://') to the link:
document.getElementById('linkname').setAttribute("href", "https://www.amazon.de");
It seems you are missing 'http://' or 'https://'