Below code creates the image in the bottom of the same page. How to display that image into a new tab/window instead of displaying in the same page?
success: function (data) { var image = new Image(); image.src = "data:image/jpg;base64," + data.d; document.body.appendChild(image); }
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.
Note that you can also middle-click "View Image" apart from Ctrl + left-click to open the image in as new tab. Note that you can also middle-click "View Image" apart from Ctrl + left-click to open the image in as new tab.
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
something like:
success: function (data) { var image = new Image(); image.src = "data:image/jpg;base64," + data.d; var w = window.open(""); w.document.write(image.outerHTML); }
Current suggestions were not working on chrome, I was always getting a white page, now I am using
const base64ImageData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; const contentType = 'image/png'; const byteCharacters = atob(base64ImageData.substr(`data:${contentType};base64,`.length)); const byteArrays = []; for (let offset = 0; offset < byteCharacters.length; offset += 1024) { const slice = byteCharacters.slice(offset, offset + 1024); const byteNumbers = new Array(slice.length); for (let i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); } const byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray); } const blob = new Blob(byteArrays, {type: contentType}); const blobUrl = URL.createObjectURL(blob); window.open(blobUrl, '_blank');
Thanks to Jeremy!
https://stackoverflow.com/a/16245768/8270748
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