admin管理员组文章数量:1315775
I'm totally new to JS. I'm trying to make me a bookmarklet that finds all images on a web page and adds a colorful border to them. Then, by clicking on an image I'd like to attach the image path. This is what I've got so far:
javascript:
for (var i= document.links.length; i-->0;) {
if (document.links[i].getElementsByTagName('img').length!=0) {
document.links[i].onclick= function() {
window.open("=" + this.src + "");
};
}
}
How can I add a border to the images?
Thanks, Bob
I'm totally new to JS. I'm trying to make me a bookmarklet that finds all images on a web page and adds a colorful border to them. Then, by clicking on an image I'd like to attach the image path. This is what I've got so far:
javascript:
for (var i= document.links.length; i-->0;) {
if (document.links[i].getElementsByTagName('img').length!=0) {
document.links[i].onclick= function() {
window.open("http://www.example./whatever?imgsrc=" + this.src + "");
};
}
}
How can I add a border to the images?
Thanks, Bob
Share Improve this question edited Mar 1, 2011 at 23:19 user142019 asked Mar 1, 2011 at 23:11 MichaelMichael 3272 gold badges6 silver badges12 bronze badges 1- your English isn't bad. You've only made one big mistake (than instead of then). I've seen worse. By the way, all images of a website or a web page? Those are two different things. – user142019 Commented Mar 1, 2011 at 23:18
2 Answers
Reset to default 2Try this code:
javascript:for(i=0;i<document.getElementsByTagName('img').length;i++){var imgTag=document.getElementsByTagName('img')[i];imgTag.style.border='2px solid #E8272C';imgTag.onclick=function(){return !window.open(this.src)};}void(0)
Friendly formatted view:
javascript:
for(i=0;i<document.getElementsByTagName('img').length;i++){
var imgTag=document.getElementsByTagName('img')[i];
imgTag.style.border='2px solid #E8272C';
imgTag.onclick=function(){
return !window.open(this.src);
}
}void(0)
There is no need to call getElementsByTagName
javascript:(function(){for(var i=0;i<document.images.length;i++){var image=document.images[i];image.style.border='medium solid blue';image.onclick=function(){location.href=this.src;return false;};}})()
本文标签: javascriptAdd border to imagesStack Overflow
版权声明:本文标题:javascript - Add border to images - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741991738a2409242.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论