javascripturlreplaceblogger

How to replace a mass old urls to new urls in blogspot with javascript


I'm a user of blogger. And my blog have very much url links image and video from others site (their allow embed their links). And now their has change the domain so all old url links no longer works.

Now I need a script can replace all them, because my blog have too much posts (2000+ posts), I cant replace all them with manual edit.

So everyone can help me do a script to fix this?

The old URL is format is: 123456.com/abc

I want replace it to new url format is: 67890.com/abc

I really glad when everyone can help me, thanks and sorry my suck english.

A script can replace the old urlto new url in blogspot


Solution

  • The code selects all img and video elements on the page, replaces the url from "123456.com" to "67890.com" in each element's src attribute.

    var elements = document.querySelectorAll('img, video');
    elements.forEach(element => {
      var src = element.src;
      src = src.replace('123456.com', '67890.com');
      element.src = src;
    });
    <img src="123456.com/1">
    <img src="123456.com/2">
    <img src="123456.com/3">
    
    <video src="123456.com/1"></video>
    <video src="123456.com/2"></video>
    <video src="123456.com/3"></video>