我有一些简单的代码,可以在新窗口中打开嵌入的img:
<img onclick="window.open(this.src, 'child'); return true;" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAYE">
现在我正在寻找同样的技巧,但对于背景图像,我已经尝试过了,但背景图像是空的
<td onclick="window.open(this.style.backgroundImage, 'child');" background="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgA"></td>
您应该声明您的背景如下:
style="background-image: url(data:image ... );"
但是,请注意,如果您打算使用更大的图像,您将尝试打开的URI可能太大。
您必须从背景中切片图像url。如下:
<td onclick="window.open(this.style.background.slice(4, -1), 'child'); return true;" style="background:url('http://upload.wikimedia.org/wikipedia/commons/b/b7/Big_smile.png')"></td>