开发者

How to link an image and target a new window

I have a picture, if I click onto that pict开发者_开发知识库ure, 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?


<a href="http://www.google.com" target="_blank">
  <img width="220" height="250" border="0" align="center"  src=""/>
</a>


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.


<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


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


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


To open in a new tab use:

target = "_blank"

To open in the same tab use:

target = "_self"


Try this simple solution

<a href="path/of/your/image/image.png" target="_blank">
    <img src="path/of/your/image/image.png" alt=""
        style="width: 37rem;max-width: 100%;height: auto;vertical-align: 
        middle;border-style: none;">
</a>

See live https://codepen.io/awaisaslampro/pen/abwOPrP


If the question is about to click on Image and open in New Tab like this

How to link an image and target a new window

Here is the code:

<a href="assets/images/android-chrome-512x512.png" target="_blank">
    <img width="220" height="250" border="0" align="center"  src="assets/images/android-chrome-512x512.png" alt=""/>
  </a>

Both the href and and src attributes values/URL's can be local for testing and incase of live site.. it should be live link to access

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜