admin管理员组文章数量:1356342
I am trying to display the image directly in HTML through a dynamic link I generated by Javascript.
function dynamicUrl() {
var url = "" + dynamic_variables + ".jpg";
return url;}
Most of my research, people display image by click on buttons or what I can do for now is link to the image.
<a href="javascript:window.location=dynamicUrl();">test</a>
Anyone know how to directly display the image using the dynamic URL? Thanks!
I am trying to display the image directly in HTML through a dynamic link I generated by Javascript.
function dynamicUrl() {
var url = "http://xxx.xxx.xxx" + dynamic_variables + ".jpg";
return url;}
Most of my research, people display image by click on buttons or what I can do for now is link to the image.
<a href="javascript:window.location=dynamicUrl();">test</a>
Anyone know how to directly display the image using the dynamic URL? Thanks!
Share Improve this question asked Jun 3, 2017 at 7:51 Johns M TsaiJohns M Tsai 231 gold badge1 silver badge5 bronze badges3 Answers
Reset to default 4Dynamic create DOM for example:
function dynamicUrl() {
var url = "https://is1-ssl.mzstatic./image/thumb/Purple111/v4/dd/95/7e/dd957e3a-abd3-da8a-2211-726a67108938/source/256x256bb.jpg";
return url;
}
var img = document.createElement("img");
img.src = dynamicUrl();
document.body.appendChild(img);
Manipulate DOM to dynamic change img
url:
function dynamicUrl() {
var url = "https://www.62icon./client/assets/img/like-icon.svg";
var img = document.getElementById('imageid');
img.src = url;
}
<div>
<p>Image goes here</p>
<button onclick="dynamicUrl()">Change Image</button>
</div>
<img id="imageid" src="https://is1-ssl.mzstatic./image/thumb/Purple111/v4/dd/95/7e/dd957e3a-abd3-da8a-2211-726a67108938/source/256x256bb.jpg" />
Adding a id for the link element
<a id="link" href="">test</a>
Using click event of link element
var link = document.getElementById("link");
link.onclick = function goToDynamicUrl() {
var url = "https://image.flaticon./teams/new/1-freepik.jpg";
window.location.href = url;
}
Here is another method:
<div id="dimg">Here add image</div>
<script>
var dimg = document.getElementById('dimg');
function addImg(dv){
dimg.innerHTML ='<img src="http://xxx.xxx.xxx'+ dv +'.jpg'" >';
}
addImg('imgname');
</script>
本文标签: How to display dynamic url image in html from which created by javascriptStack Overflow
版权声明:本文标题:How to display dynamic url image in html from which created by javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744053388a2582797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论