Search code examples
bloggerwebp

Insert parameter into image url


How would I change image source url on Blogger with Javascript so that -rw is automatically inserted into the source link?

Thanks in advance.

Example:

https://lh3.googleusercontent.com/-LHNMiXVhzpY/X1w4qcb7obI/AAAAAAAAcQo/ZbgexrQWiWsOA-DMWTadR59I0478X69XgCLcBGAsYHQ/s1600/1599879340682277-0.png

To

https://lh3.googleusercontent.com/-LHNMiXVhzpY/X1w4qcb7obI/AAAAAAAAcQo/ZbgexrQWiWsOA-DMWTadR59I0478X69XgCLcBGAsYHQ/s1600-rw/1599879340682277-0.png


Solution

  • This sounds like something that would be better achieved in the Blogger side of things rather than manipulated on the client side. But if you have ruled out changing this at the server side it would be possible with Javascript.

    document.querySelectorAll('img').forEach(function(item) {
        item.src = item.src.replace(/s1600/gi, "s1600-rw");
      })
    

    This will find all img tags and search the source (src) attribute for the s1600 and replace with s1600-rw.