java - How to replace a value of an attribute in JS function on run time? -
i working on java application (besides other things) produces html. in html need change value of 1 attribute inside 1 js function every time run it. process this:
1. every time run html, application connect mysql database , retrieves needed values. 2. values parsed html , replacing keywords set purpose of replacing.
i have done replacing text defining keyword datatext
in html
<p>datatext</p>
and in java application, made replacing this:
public void visitstringnode (text string) { ... else if (string.gettext().equals("datatext")){ string.settext(text); } }
where text
string retrieved database. wanted same replacing value of 1 attribute within js function setting keyword datavideo
:
function replacesrcc() { var elem = document.getelementsbytagname("embed")[0]; copy = elem.clonenode(); copy.src = datavideo; elem.parentnode.replacechild(copy, elem); }
and in java make replacing in previous case:
else if (string.gettext().equals("datavideo")){ string.settext(video_link); }
where video_link
string containing youtube link retrieved database. this, however, not work. debugging says fails search datavideo
keyworkd within html. suggestions?
edit : function replacesrcc() called on page load, this:
<script> function replacesrcc() { var elem = document.getelementsbytagname("embed")[0]; copy = elem.clonenode(); copy.src = "https://www.youtube.com/v/skqennnt_vg?version=3"; elem.parentnode.replacechild(copy, elem); } if (window.addeventlistener){ window.addeventlistener('load', replacesrcc, false); } else if (window.attachevent) { window.attachevent('onload', replacesrcc); } </script>
Comments
Post a Comment