点击图片地址,应用window.open()和document.write()关上新窗口,实现图片预览,单击右键进行保留

const imgWindow = window.open('')imgWindow && imgWindow.document.write(`<img src='${url}' style='display: flex; margin: 0 auto'/>`)

后果发现,在局部谷歌浏览器中,新窗口关上后无奈实现单击右键进行图片保留。而选“在新标签页中关上图片”却能够。为什么会这样?

在网上搜寻一番,网友说是谷歌内核的起因导致,给出解决方案 xxx.document.location = "#"
https://qa.1r1g.com/sf/ask/28...

const imgWindow = window.open('')imgWindow && imgWindow.document.write(`<img src='${url}' style='display: flex; margin: 0 auto'/>`)imgWindow.document.location = "#";

问题解决了,然而具体是啥起因,还不分明,而且不晓得为啥要用 document.location并且设置为 #,才会起作用,心愿大佬看到后解个惑