**List of steps to reproduce** (step by step, including full links if applicable):
* Copy https://en.wikipedia.org/wiki/2021_UEFA_Champions_League_Final#/media/File:20191002_Fu%C3%9Fball,_M%C3%A4nner,_UEFA_Champions_League,_RB_Leipzig_-_Olympique_Lyonnais_by_Stepro_StP_0043-2.jpg and past to location bar. Then press enter.
* Click X button on the top-right corner
**What happens?**:
Clicking the "X" button should go to the article this media is in, in this case, https://en.wikipedia.org/wiki/2021_UEFA_Champions_League_Final
**What should have happened instead?**:
Currently, clicking "X" button will just go back to your previous page (probably accomplished by something like `window.history.go(-1);`?). This is counterintuitive.
This seems to happen whenever you visit the link with no referer. Pasting it to location bar is just a easier way to reproduce it.
In my case I opened it from my browser's history.
Or you can create an HTML with
```
lang=html
<a href="https://en.wikipedia.org/wiki/2021_UEFA_Champions_League_Final#/media/File:20191002_Fu%C3%9Fball,_M%C3%A4nner,_UEFA_Champions_League,_RB_Leipzig_-_Olympique_Lyonnais_by_Stepro_StP_0043-2.jpg" rel="noreferrer">test link</a>
```
**Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc**:
Google Chrome Version 91.0.4472.77 (Official Build) (64-bit)