Monday 26 October 2020

Open inline SVG in new window - Javascript

I have a <div> that contains an inline svg. I would like a function that opens that svg in a new tab/window. I only want to use the front-end js without having to save the svg anywhere.

If I use window.open(), it puts the svg inside an <html> tag which I'm trying to avoid.

I'm basically trying to change this answer but then only have the svg code left: https://stackoverflow.com/a/21667339/1083923

//---print button---
    var printSVG = function()
    {
        var popUpAndPrint = function()
        {
            var container = $('#svgDiv');
            var width = parseFloat(container.getAttribute("width"))
            var height = parseFloat(container.getAttribute("height"))
            var printWindow = window.open('', 'PrintMap',
            'width=' + width + ',height=' + height);
            printWindow.document.writeln($(container).html());
            printWindow.document.close();
            printWindow.print();
            printWindow.close();
        };
        setTimeout(popUpAndPrint, 500);
    };


from Open inline SVG in new window - Javascript

No comments:

Post a Comment