Is there any solution to disable cookies for images loaded from third-party domains using HTML5 or JavaScript techniques?
I'm looking for something similar to sandbox
attribute for <iframe>
tag, referrerpolicy
or crossorigin
attributes for <img>
tag.
Using jQuery, you can either hide the image : $("#hrefId"). hide() or add a CSS class that would style it as being disabled : $("#hrefId"). addClass("disabled") ...
To block third-party cookies set with iframe (like YouTube videos), find an iframe code that is setting third-party cookies and: change src attribute name to data-src. add data-cookiescript attribute and set it to accepted.
Try below code: cookieExpire = new Date(); cookieExpire. setMonth(cookieExpire. getMonth() + 10);
Update: This workaround no longer works for:
After several days of challenge with this issue, I can confirm this can not be done using the <img>
tag and any currently available techniques.
The right way is to use cookieless proxy server for images like Google does, but this is too resource intensive for us at this moment.
Acceptable workaround:
<img>
with <iframe
sandbox
>
;<iframe>
use Data URI with inline CSS;<img>
tag sizing behavior use CSS background-size: cover
which scales the image, this allows to set width and height to the <iframe>
which applies to the inner image;role="img"
and aria-label
as alt
replacement.Example:
<img width="100" height="75" alt="About company" src="https://www.dtm.io/wp-content/uploads/2018/04/datamart-company.png" /> <iframe width="100" height="75" aria-label="About company" role="img" frameborder="0" sandbox src="data:text/html,<style>body{background:url('https://www.dtm.io/wp-content/uploads/2018/04/datamart-company.png') center/cover no-repeat;padding:0;margin:0;overflow:hidden}</style>"></iframe>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With