How to link an image and target a new window

后端 未结 6 1402
孤城傲影
孤城傲影 2020-12-10 23:33

I have a picture, if I click onto that picture, how can I build an image reference so another page opens in a new tab or a new window of my browser displaying the picture?

相关标签:
6条回答
  • 2020-12-11 00:15

    If you use script to navigate to the page, use the open method with the target _blank to open a new window / tab:

    <img src="..." alt="..." onclick="window.open('anotherpage.html', '_blank');" />
    

    However, if you want search engines to find the page, you should just wrap the image in a regular link instead.

    0 讨论(0)
  • 2020-12-11 00:17

    To open in a new tab use:

    target = "_blank"
    

    To open in the same tab use:

    target = "_self"
    
    0 讨论(0)
  • 2020-12-11 00:25

    Assuming you want to show an Image thumbnail which is 50x50 pixels and link to the the actual image you can do

    <a href="path/to/image.jpg" alt="Image description" target="_blank" style="display: inline-block; width: 50px; height; 50px; background-image: url('path/to/image.jpg');"></a>
    

    Of course it's best to give that link a class or id and put it in your css

    0 讨论(0)
  • 2020-12-11 00:26

    you can do like this

    <a href="http://www.w3c.org/" target="_blank">W3C Home Page</a>
    

    find this page

    http://www.corelangs.com/html/links/new-window.html
    

    goreb

    0 讨论(0)
  • 2020-12-11 00:29
    <a href="http://www.google.com" target="_blank"> //gives blank window
    <img width="220" height="250" border="0" align="center"  src=""/> // show image into new window
    </a>
    

    See the code

    0 讨论(0)
  • 2020-12-11 00:31
    <a href="http://www.google.com" target="_blank">
      <img width="220" height="250" border="0" align="center"  src=""/>
    </a>
    
    0 讨论(0)
提交回复
热议问题