你有相同的事件触发,所以如果你打开页面已经有 html window
,你可以得到load事件,例如
var b = new Blob([clonedElement.html()], {type: 'text/html'}),
uri = URL.createObjectURL(b),
printWindow;
printWindow = window.open(uri, '_blank');
printWindow.addEventListener('load', function () {
URL.revokeObjectURL(uri); // release these
b = null; // from memory
// do something else
});
请注意,这里会有一个竞争条件(尽管您几乎总是会赢得它,即如果页面加载并且事件在打开和添加侦听器之间触发)
或者,没有比赛
var b = new Blob([clonedElement.html()], {type: 'text/html'}),
uri = URL.createObjectURL(b),
printWindow = window.open('', '_blank');
printWindow.addEventListener('load', function () {
URL.revokeObjectURL(uri); // release these
b = null; // from memory
// do something else
});
printWindow.location = uri;