I have a simple app that fetches images from Unsplash API. I would like users to click on the image, and download it and also maybe for the image to open in a new tab too.
The urls.regular is just a simple url like https://images.unsplash.com/photo-1543332164-6e82f355badc?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjE3OTUzOH0
After reading other issues on stackoverflow, I added "download" at the end of my a tag.
<div>
<a href={urls.regular} title={description} download>
<img
src={urls.regular}
/>
</a>
</div>
I have also tried the following in my a tag:
href={urls.regular}
target="_blank"
rel="noopener noreferrer"
download={urls.regular}
You should define onclick event for the a tag.
<a href={urls.regular} title={description} download onclick="onClick(urls.regular)">
function onClick(url) {
window.open(url, '_blank');
}
Related
I'm learning HTML.
I've following code piece:
<a href="#B" id="specialClass" class="primary-btn icon-cart" data-one="#A" data-five="google.com" data-ten="#C" target="_blank">
<span id="pressButton">New Button</span>
</a>
When I press button based on slider and data-five gets triggered, I for some reason open in a new tab mywebsite.com/google.com instead of google.com.
What am I doing wrong?
If it is an address outside your web page you have to put the full path with https://google.es
<a target="_blank" href="https://google.es">Google</a>
i am using this inside Modal:
<a target="_blank"
id="changeme"
rel="noopener noreferrer"
href="javascript:void(0)"
>
Visit Site here
</a>
but it still opens a new tab. Other answers were without target="_blank" tag.
Is it possible without using JS to make the link does nothing when clicked?
below are two links with download attribute.
clicking on both gives different result, why?
<a href="https://www.w3schools.com/images/myw3schoolsimage.jpg" download>
dnld
</a>
<br>
<a href="https://scontent.xx.fbcdn.net/v/t45.1600-4/28204217_6081249221877_6688541583534456832_n.png?oh=9262305ce4d55f669767f01c1be364b1&oe=5B06C1A9" download >Download</a>
w3schools link downloads the image where as the other one simply opens the image.
because the extension should be displayed at end of url
<a href="https://www.w3schools.com/images/myw3schoolsimage.jpg" download>
dnld
</a>
<br>
<a href="https://scontent.xx.fbcdn.net/v/t45.1600-4/28204217_6081249221877_6688541583534456832_n.png" download >Download</a>
I've added a page link to a picture for my website, but it does not load the website because the link goes the directory therefore the webpages do not appear. My code is below:
<a href="www.w3schools.com">
<img src="Images/insta.png" alt="" style="width:7%; height:7%;">
</a>
When I click on the image it says file not found.
If you're linking to a page on an external site, you will need to provide the entire URL of the page in question, which includes the protocol. In this instance, that would be http://www.w3schools.com/.
By linking to www.w3schools.com, you are telling the browser to load that URL relative to the page you're linking from so, if this link were on a page located at http://domain.tld/page.html, clicking on it would attempt to load http://domain.tld/www.w3schools.com.
Add http:// OR https:// for your website link:
<a href="http://www.w3schools.com/">
<img src="Images/insta.png" alt="" style="width:7%; height:7%;">
</a>
<a href="http://www.w3schools.com" target="_blank">
<img src="Images/insta.png" alt="" style="width:7%; height:7%;">
</a>
Without the http:// your link will be something like: youraddress/www.w3schools.com
And pay attention if you image is in the correct folder called Images
I there a way to show popup texts while clicking the youtube video iframe code ?
<a href='login.html?sid=0&keepThis=true&TB_iframe=true&height=240&width=650' class="thickbox" title='test'>
Have you try to call Javascript on the onclick attribute
<a onclick="alert('test')"
href='login.html?sid=0&keepThis=true&TB_iframe=true&height=240&width=650' class="thickbox" title='test' >
This will open the pop up and then go to the URL (tested on Firefox 7).
Edit: Another solution is to do the href location after the pop up :
<a onclick="alert('test');document.location.href='login.html?sid=0&keepThis=true&TB_iframe=true&height=240&width=650'"
class="thickbox" title='test'>