如何替换html中所有出现的图像url

发布于 2024-12-07 17:44:55 字数 223 浏览 0 评论 0原文

我有一个博主博客。我在我的每一篇博客文章(我的签名)中都放了一张图片。早些时候它托管在图像托管网站上,但现在我希望它把它放在我自己的网站上,因为旧托管网站可能随时删除它。如何用新的 url 替换所有出现的图像先前的 url,而无需在每个帖子中手动更改它?

手动完成几乎是不可能的,因为我已经发布了一百多个帖子。

就像我可以在模板中插入任何代码一样,每当打开页面时,该代码都会用新的网址替换以前的网址?

i have a blogger blog. there is one image which i put in each of my blog's post( of my signature). earlier it was hosted on an image hosting site but now i want it to put it on my own site since the old hosting site may delete it any time. how can i replace all occurrences of the image previous url with the new url without changing it manually in each post?

it is almost impossible to do it manually because i already have made more than a hundred posts.

like is there any code which i can insert in the template which will replace the previous url with the new one whenever a page is opened?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我做我的改变 2024-12-14 17:44:55

使用 jQuery: -

$("a").each(function() {
var existingURI = $(this).attr('href');
    $(this).attr('href', './path_to_new_location/' + existingURI);

});

如果您不确定如何使用 jQuery,请在此处发表评论,我将为您提供帮助。 Js Fiddle在这里: http://jsfiddle.net/jTnpk/

With jQuery: -

$("a").each(function() {
var existingURI = $(this).attr('href');
    $(this).attr('href', './path_to_new_location/' + existingURI);

});

If you're not sure how to use jQuery comment here and i'll give you a hand. Js Fiddle here: http://jsfiddle.net/jTnpk/

悸初 2024-12-14 17:44:55

您是否能够复制博客的所有 HTML 内容,因为如果您能够,那么您可以简单地将它们粘贴到任何好的文本编辑软件中,例如 记事本++
从那里,您可以在搜索下转到“替换...”,在一个中输入旧链接,在另一个中输入新链接后,点击“全部替换”,然后您可以复制所有代码并将其粘贴回来,如果您有该选项,如果没有,您可以向页面添加一个脚本,其内容如下所示:

<script>
for(i=0;i<document.links.length;i++)
{
if(document.links[i].href == /*Insert old link here*/)
    document.links[i].href = /*Insert new link here*/ ;
}
</script>

Are you able to copy all of your blog's HTML contents, because if you were able to then you could simply paste them into any good text editing software like Notepad++
from there you could go to "Replace..." under search and after typing in the old link in one and the new link in the other hit "Replace All" and from there you could just copy all the code and paste it back, if you have that option, if not you could add a script to the page which goes a little something like this:

<script>
for(i=0;i<document.links.length;i++)
{
if(document.links[i].href == /*Insert old link here*/)
    document.links[i].href = /*Insert new link here*/ ;
}
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文