Define image src tag using portion of an URL using JavaScript -


with code below, able variable without slash url html.

    var patharray = location.pathname.split( '-' );     var urlwithoutdashes = patharray[0];     var urlwithoutslash = urlwithoutdashes.substring(1);     document.write(urlwithoutslash); 

now i'd use img src tag (with extention .png), can't figure out how it. code below doesn't seem work.

    var patharray = location.pathname.split( '-' );     var urlwithoutdashes = patharray[0];     var urlwithoutslash = urlwithoutdashes.substring(1);     document.write("img src=\""urlwithoutslash".png\">"); 

how can solve this?

this line:

document.write("img src=\""urlwithoutslash".png\">"); 

should be:

document.write("<img src=\"" + urlwithoutslash + ".png\">"); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -