'View instead of downloading an image in new chrome tab using JS

I am creating a chrome extension that will open a link to an image in a new tab.

However I am coming across links that will automatically download the image instead of viewing it in the new chrome tab.

I am using the following code to do create the new tab:

chrome.tabs.create({ url: url_to_open, active: false});

Example of "unviewable" image from vsco: "im.vsco.co/aws-us-west-2/de89e8/880500/627c05d3edd24e3c58174876/vsco_051122.jpg?w=749&dpr=1"

Is there any way to not automatically download the image but view it instead?

Thanks!



Solution 1:[1]

You can simply create a link element that opens a new tab on click.

let ln = document.createElement('a');
ln.href = 'url here';
ln.setAtrribute('target', '_blank');
ln.click();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Praise Dare