"Save image as.." not working in Google Chrome when using window.open() and document.write() "Save image as.." not working in Google Chrome when using window.open() and document.write() google-chrome google-chrome

"Save image as.." not working in Google Chrome when using window.open() and document.write()


I found a solution that seems to work. Make the tab have a location attribute. I'm not sure why this is needed, but it works for me on Chrome 48.

document.write('<html><head>    <title></title>    <script>        function foo() {            var tab = window.open();            tab.document.write('<p>Right-click, then click "Save image as ..."</p><img src="http://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png" />');            tab.document.location = "#";        }    </script></head><body>    <button onclick="foo();">Open</button></body></html>');