Reputation: 2460
I am attempting to create a link dynamically using javascript, but the host url is prepended to the link every time. How do I stop this from happening. I created an example on js fiddle. the link created prepends "http://fiddle.jshell.net/mTgtr/show/" to the www.google.com link.
var eventLink = "www.google.com";
var elEventBlock = document.createElement('div');
var elA = document.createElement('a');
elA.setAttribute('href', eventLink);
elA.setAttribute('target', '_blank');
elA.innerHTML = "test";
document.getElementById("myDiv").appendChild(elA);
Upvotes: 1
Views: 1808
Reputation: 45083
You should prefix the URL with the protocol, such as http://
, https://
, ftp://
, etc.
Upvotes: 5