2
votes

I have a website and I want it to fit into html img tags so that the img tag will work.

For example, open bracket img src = "https://api.thecatapi.com/v1/images/search?format=src" close bracket is the line that will give you a picture of a cat.

I tried to do something similar by making a website, that redirects another website hosting one picture from a list using the window.location.replace function, however, plugging my website into the src isn't cutting it.

What functions/code can I use to allow my url to be used in img tags?

4

4 Answers

1
votes

if you want to embed link to image( clickable image ) :

<a href="google.com">
  <img src="myImage.png" style="width:42px;height:42px;border:0;">
</a>

if you want to display image from link

<img src="https://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com">

Explained Here : https://www.w3schools.com/html/html_images.asp

if you want to open an image in a new tab

<a href="www.google.com" target="_blank">
  <img width="250" height="250" border="0" align="center"  src=""/> //image to show in the new window
</a>
0
votes

Didn't understand the question completely but window.location.replace won't help you display or redirect as this is a window object in the browser and location represents the URL state. So, if you want to display an image which you get by redirecting just use href attribute while placing the img tag in an anchor tag(). Hope this would help.

0
votes
  • You mean that :
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    <div>
        <img src="https://api.thecatapi.com/v1/images/search?format=src" alt="">
    </div>

</body>
</html>
0
votes

Apparently, I need a 302 redirect to have the url be part of img tags. Edit: found my answer here How can I redirect my homepage to a random url through firebase hosting?. This will enable me to use my homepage in img tags.