Home > Blockchain >  Linking an image source based on base64
Linking an image source based on base64

Time:03-20


I've been working on a chatroom project using node.js with the ability to send images. I was able to convert the image uploaded by the user, but I want to make it so that when you click it, it opens the source into a new tab. However, when I click it, it opens in an about:blank page. When I check the console of the about:blank page, I get this error message:
Error

Here's the code I used for the source and the link.

Code


Anyone know what the issue is? Thanks

CodePudding user response:

This should get around it and achieve the same thing..

<html>

    <script>
    
        function openDataUrl(base64URL){
            let aWindow = window.open();

            aWindow.document.write('<iframe src="'   base64URL    '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>');
        }
    
    </script>

    <body>
        <a href="javascript:void();" onclick="openDataUrl('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAMAAADXqc3KAAAB FBMVEUAAAA/mUPidDHiLi5Cn0XkNTPmeUrkdUg/m0Q0pEfcpSbwaVdKskg lUP4zA/iLi3msSHkOjVAmETdJSjtYFE/lkPnRj3sWUs8kkLeqCVIq0fxvhXqUkbVmSjwa1n1yBLepyX1xxP0xRXqUkboST9KukpHpUbuvRrzrhF/ljbwaljuZFM4jELaoSdLtElJrUj1xxP6zwzfqSU4i0HYnydMtUlIqUfywxb60AxZqEXaoifgMCXptR9MtklHpEY2iUHWnSjvvRr70QujkC pUC/90glMuEnlOjVMt0j70QriLS1LtEnnRj3qUUXfIidOjsxAhcZFo0bjNDH0xxNLr0dIrUdmntVTkMoyfL8jcLBRuErhJyrgKyb4zA/5zg3tYFBBmUTmQTnhMinruBzvvhnxwxZ/st Ktt5zp9hqota2vtK6y9FemNBblc9HiMiTtMbFtsM6gcPV2r6dwroseLrMrbQrdLGdyKoobKbo3Zh ynrgVllZulTsXE3rV0pIqUf42UVUo0JyjEHoS0HmsiHRGR/lmRz/1hjqnxjvpRWfwtOhusaz0LRGf7FEfbDVmqHXlJeW0pbXq5bec3fX0nTnzmuJuWvhoFFhm0FtrziBsjaAaDCYWC uSi6jQS3FsSfLJiTir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