Create anchor href with javascript and not have host url in link -
i attempting create link dynamically using javascript, host url prepended link every time. how stop happening. created example on js fiddle. link created prepends "http://fiddle.jshell.net/mtgtr/show/" 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);
you should prefix url protocol, such http://
, https://
, ftp://
, etc.
Comments
Post a Comment