- From: Ian Hickson <ian@hixie.ch>
- Date: Wed, 11 May 2011 22:56:57 +0000 (UTC)
On Tue, 8 Feb 2011, Andreas G?bel wrote: > > Recently I needed to have some base64 encoded images to show in a new > window. My first attempt was, to just pass the > data:image/png;base64,<data> string as first argument from > window.open(). > > This works in all browsers that support data-uris, but it is terribly > slowing down the browser when passing in images with a "big" filesize. In new UAs, a possibly better solution is to do a window.open() of the URL obtained from URL.createBlobURL() using a Blob containing the image (assuming you have a blob version of the image somehow -- not sure how you got the base64 contents). > My idea was to do something like this: > > var largeprev = window.open('data:text/html;charset=utf-8,' + escape('<div/>'), 'large'), > that = this; > > largeprev.addEventListener('DOMContentLoaded', function(e) { > largeprev.alert('loaded'); > largeprev.document.querySelectorAll('div')[0].appendChild(that); > }, false); > > this works great in Firefox (3.6.x), but Chrome and Safari treat the > returned DOMWindow object like it represents a foreign domain. Yeah, that's a known bug in WebKit that they plan to fix one day but that is hard to fix. You can just open 'about:blank' in the meantime, it has much the same effect: var win = window.open('about:blank'); win.document.body.appendChild(this); ...or some such. On Wed, 9 Feb 2011, Andreas G?bel wrote: > > Well it's not an option for me to use a browser setting / commandline > argument to make this work. The only way I'm aware of is to use > document.write() like > > > var virtualdom = '<html><body><img src="' + 'data:image/png;base64,R0lDWRW...' + '"/></body></html>', > prev = window.open('', 'large'); > > prev.document.open(); > prev.document.write(virtualdom); > prev.document.close(); > > in order to make this work. That would work too, yes. ('' is the same as 'about:blank' here.) On Tue, 8 Feb 2011, Mihai Parparita wrote: > > I believe you're running into http://crbug.com/58999 That's the one. -- Ian Hickson U+1047E )\._.,--....,'``. fL http://ln.hixie.ch/ U+263A /, _.. \ _\ ;`._ ,. Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 11 May 2011 15:56:57 UTC