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.

http://jsfiddle.net/mtgtr/

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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -