最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use base url for image source htmljs - Stack Overflow

programmeradmin3浏览0评论

Hey i get my html content via json. The image blocks look like:

src=\"/2017/03/test.jpg\" alt=\"test\" width=\"576\" height=\"800\" srcset=\"/2017/03/test.jpg 576w, /2017/03/test-112x155.jpg 112w, /2017/03/test-432x600.jpg 432w\" 

The src should look like mywebsite/img-src but it looks like localhost/img-src right now...

I tried to replace it via JavaScript but then it looks like: localhost/mywebsite/img-src

Does somebody have an idea

Edit: the image is hosted on ONE Website! And it should be shown on every device. Now its 404...

Hey i get my html content via json. The image blocks look like:

src=\"/2017/03/test.jpg\" alt=\"test\" width=\"576\" height=\"800\" srcset=\"/2017/03/test.jpg 576w, /2017/03/test-112x155.jpg 112w, /2017/03/test-432x600.jpg 432w\" 

The src should look like mywebsite./img-src but it looks like localhost/img-src right now...

I tried to replace it via JavaScript but then it looks like: localhost/mywebsite./img-src

Does somebody have an idea

Edit: the image is hosted on ONE Website! And it should be shown on every device. Now its 404...

Share Improve this question edited Mar 7, 2017 at 15:36 lostluke asked Mar 7, 2017 at 15:24 lostlukelostluke 1651 gold badge4 silver badges13 bronze badges 3
  • I'm unclear about what the problem is. May you edit your question to be clearer? – evolutionxbox Commented Mar 7, 2017 at 15:28
  • Either append the URL before it populates the source of your image, or use JS to find all the images and change their source to include it. – Waxi Commented Mar 7, 2017 at 15:29
  • 1 I would suggest do not touch src. If server returns response like this then it is meant to look like this. Instead, if you're working on localhost create virtual host, for example dev.mysite. configure Apache to point it to subfolder, for example /var/www/html/mysite/img-src – lomboboo Commented Mar 7, 2017 at 15:32
Add a ment  | 

1 Answer 1

Reset to default 5

It can be done by including a <base> tag in the <head> tag like this:

<base href="mywebsite./path">

For more information reference this webpage: https://www.w3schools./tags/tag_base.asp

发布评论

评论列表(0)

  1. 暂无评论