[英]Changing the url of image src
I'm trying to change to source of the images shown in a page. 我正在尝试更改页面中显示的图像的来源。
I've got this code: 我有以下代码:
function replaceSRC(){
var allImg=document.getElementsByTagName('img'), i=0, img;
while(img=allImg[i++]){
img.src=img.src.replace(\'//dyncdn.me/static/over/, "\'//dyncdn.me/static/poster/3/");
}
}
Not sure what to do next, im not really a script person i just wanted to make a site that uses to many small preview images to be seen bigger thats all. 不知道下一步该怎么做,我不是一个真正的脚本人,我只是想做一个网站,使用很多小的预览图像就可以看到更大的内容。
the original source is: 原始来源是:
dyncdn.me/static/over/random numbers.jpg
the source i want to use is: 我想使用的来源是:
dyncdn.me/static/poster/3/same random numbers.jpg
anyone can help out? 任何人都可以帮忙吗? thanks!
谢谢!
edit #1: seems the site is using onmouseover string to get the image source, while mouseout nothing shows. 编辑#1:似乎该网站正在使用onmouseover字符串来获取图像源,而mouseout则什么也没有显示。 (only when my mouse is over the title the image is shown).
(仅当鼠标悬停在标题上方时,才会显示图像)。
Your string syntax is wrong. 您的字符串语法错误。 The replace line should be:
替换行应为:
img.src=img.src.replace("//dyncdn.me/static/over/", "//dyncdn.me/static/poster/3/");
Create a bookmark and change the URL to this 创建一个书签并将URL更改为此
javascript:(function(){var imgs = document.getElementsByTagName("img"); for (var i=0;i<imgs.length;i++) { var src=imgs[i].src; if (src.indexOf('static/over')!=-1) imgs[i].src=src.replace("/over/","/poster/3/")}})()
Now click F12 to open the console, click the bookmark on the page you need to change and report any errors you see 现在单击F12打开控制台,单击您需要更改的页面上的书签并报告您看到的任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.