Home > other >  How to open a picture by link (<a></a>)?
How to open a picture by link (<a></a>)?

Time:01-05

I have some text which I'd like to be clickable. And I want the picture to be opened when I click the certain word in a new window (not in a new tab). How could I do that? The code below does not work.

<p>Click on the <a href = "./images/TheForm.jpg">"Request Access"</a> button and fill in the form.</p>

CodePudding user response:

<a href="IMAGE_URL" target="_blank">
  <img alt='img_path' class='img-40 rounded-circle' src='IMAGE_URL' />
</a>

CodePudding user response:

Just add a target="_blank" to your link if you want to open the destination of a link in a new tab:

<a href = "./images/TheForm.jpg" target="_blank">Request Access</a>

And define a onClick method to open it in a window :

<a href="./images/TheForm.jpg"  
    onclick="window.open('./images/TheForm.jpg', 
                         'windowName', 
                         'width=800, height=600'); 
              return false;"
 >Request Access</a>

When you specify the width/height, it'll open the link in a new window instead of a tab.

Here is the documentation for further information.

  •  Tags:  
  • Related