Is it possible to set the source of an image using the javascript: pseudo-protocol? -
basically, have context i'm allowed create image, want run script before decide on source, i'm wondering if possible:
<img src="javascript:{load remote script , run figure out source}" /> the work-around i've come is:
<img src="any-old-image.gif" onload="document.write('<scr' + 'ipt src=\"http://mysite-script.js\"'></scr' + 'pt>');" /> but i'm hoping little cleaner possible.
p.s. i'm aware "javascript:" quote-unquote evil. special situation.
create function gathers whatever data need , sends server (via xmlhttprequest, or whatever method prefer). create function examines response server , decides image use. can set url image directly:
document.getelementbyid("myimage").src = myimagesrc;   edit: addressing comment.
if can muck img element itself, right, img.onload want.  , if there's more couple of lines of script, importing script seems reasonable.  maybe little bit cleaner document.write:
document.body.appendchild(document.createelement("script")).src =     "http://mysite.com/myscript.js"; 
Comments
Post a Comment