How to prevent html img from sending referrer to server¶
When you put an image on html, the browser will request the image's data from image server. When sending the request, the browser also send a special http header Referer
whose value is a URL. Sometimes, we don't want this behavior. We have several ways to prevent it.
Once and for all¶
Update the html like the following example. Tt will influence the whole web page.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- set referrer content to never ↓ -->
<meta name="referrer" content="never">
<title>example</title>
</head>
<body>
</body>
</html>
Fine-grained¶
Only update the necessary img tag.
<!-- set img referrerpolicy to no-referrer ↓ -->
<img src="test.png" referrerpolicy="no-referrer">
This article is originally created by tooli.top. Please indicate the source when reprinting : https://www.tooli.top/posts/img_referrer
Posted on 2022-03-25
Mail to author