I am trying to open an image in a new tab using this simple code.
window.open(file.url);
The file is a .jpg file and my browser is Chrome. Instead of showing the image in a new tab it triggers the download window and asks me to download it to my PC.
Is this a javascript issue? Or is it a default Chrome setting? I have googled this for a while and some people are suggesting it could be a MIME type problem but I have no control over the image coming from the server.
Any advice would be appreciated.
When you right click on the image you need to select then 'Open image in new Tab' from the drop down and NOT 'Open link in new tab' this will then open the image in a new tab.
Press the ctrl button while you click the image, it opens the image in new tab.
You can make the link open in a new window by adding target="_blank" . The question if the PDF file is opened in the window or downloaded depends on the software the user has installed, i don't think it is possible to control that.
Sometimes we may want the linked page to open in a new browser tab or window. To do this we add target="_blank" in the first section before > . We can do this for both an image or text link. That's it – how to add a text link, image and an image link in HTML.
As suggested by @Lachlan Walls in the comments, you can open a blank tab and write a simple html with an img tag:
const image_window = window.open("", "_blank")
image_window.document.write(`
<html>
<head>
</head>
<body>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/84/Example.svg" alt="Example" height="100%" width="100%">
</body>
</html>
`);
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