【问题标题】:How do you put your url in a img tag (html)?您如何将您的网址放入 img 标签 (html) 中?
【发布时间】:2020-02-16 15:23:45
【问题描述】:

我有一个网站,我希望它适合 html img 标签,以便 img 标签可以工作。

例如,左括号 img src = "https://api.thecatapi.com/v1/images/search?format=src" 右括号是为您提供猫图片的行。

我尝试通过创建一个网站来做类似的事情,该网站使用 window.location.replace 函数重定向另一个托管列表中一张图片的网站,但是,将我的网站插入 src 并没有削减它。

我可以使用哪些函数/代码来允许我的 url 在 img 标签中使用?

【问题讨论】:

    标签: javascript html image url


    【解决方案1】:

    显然,我需要一个 302 重定向才能使 url 成为 img 标签的一部分。 编辑:在这里找到我的答案How can I redirect my homepage to a random url through firebase hosting?。 这将使我能够在 img 标签中使用我的主页。

    【讨论】:

      【解决方案2】:
      • 你的意思是:
      <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>
      

      【讨论】:

        【解决方案3】:

        如果你想嵌入图片链接(可点击图片):

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

        如果要显示链接中的图像

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

        在此解释:https://www.w3schools.com/html/html_images.asp

        如果你想在新标签页中打开图片

        <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>
        

        【讨论】:

        • 我知道如何使用图像,我只需要知道如何让我的网站(.com,而不是 .jpeg 或 .png)像例子。
        • 你找到答案了吗? ~ 你想让 img 重定向到 URL 吗?还是显示 URL 图片?
        【解决方案4】:

        没有完全理解这个问题,但 window.location.replace 不会帮助您显示或重定向,因为这是浏览器中的一个窗口对象,而 location 表示 URL 状态。因此,如果您想显示通过重定向获得的图像,只需使用 href 属性,同时将 img 标签放在锚标签()中。希望这会有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-22
          • 1970-01-01
          • 2019-01-15
          • 1970-01-01
          • 2011-06-17
          • 1970-01-01
          相关资源
          最近更新 更多