From f659d3da43be6c69695e209766c42eaf49b816d3 Mon Sep 17 00:00:00 2001 From: shannonlui Date: Thu, 23 May 2019 23:43:21 -0400 Subject: [PATCH] Open image in new tab when saving on iOS Safari because of iOS bug --- client/src/pages/ImageEditor/Canvas/Canvas.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/src/pages/ImageEditor/Canvas/Canvas.js b/client/src/pages/ImageEditor/Canvas/Canvas.js index ddc5cfd..b5faef7 100644 --- a/client/src/pages/ImageEditor/Canvas/Canvas.js +++ b/client/src/pages/ImageEditor/Canvas/Canvas.js @@ -63,8 +63,16 @@ class Canvas extends Component { } saveCanvas = () => { - const canvas = this.canvas.current; - saveAs(canvas.toDataURL('image/png'), 'pixelartify.png'); + var ua = window.navigator.userAgent; + var iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i); + var webkit = !!ua.match(/WebKit/i); + var iOSSafari = iOS && webkit && !ua.match(/CriOS/i); + const canvasURL = this.canvas.current.toDataURL('image/png'); + if (iOSSafari) { + window.open(canvasURL, '_blank'); + } else { + saveAs(canvasURL, 'pixelartify.png'); + } } getClosestColor(colors, target) {