且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

替换所有图像的图像源

更新时间:2023-12-05 17:24:22

你的正则表达式是问题,你需要用斜杠包装它(否则解释器不知道它应该把它当作正则表达式):

Your regular expression is the problem, you need to wrap it in slashes (otherwise the interpreter has no clue that it should treat that as a regexp):

var allImg=document.getElementsByTagName("img"), i=0, img;

var pattern = /^http\:\/\/aff\.kooora\.com\/(.*)$/;

while (img = allImg[i++])
{
    if (img.src.match(pattern)) {
        img.src = img.src.replace(pattern, 'http://example.com/aff.kooora.com/$1');
    }
}