Reputation: 21
Maybe it render, that took xxMS. What happen? Anytime I close the print page, I receive this message in the chrome console. Does anyone fix this problem?
<button @click="printScreen()" type="button">print</button>
<div ref="printparts">test</div>
methods: {
printScreen() {
let value = this.$refs.printparts;
let printPage = window.open();
printPage.focus();
printPage.document.body.insertAdjacentHTML('afterbegin', value.outerHTML);
printPage.print();
printPage.close();
},
},
Upvotes: 1
Views: 9349
Reputation: 21
I used onmouseover and Chrome doesn't show the violation, but Performance say Warning.
printScreen() {
let value = this.$refs.printparts;
let printPage = window.open();
printPage.focus();
printPage.document.body.insertAdjacentHTML('afterbegin', value.outerHTML);
printPage.onmouseover = function() {
printPage.print();
printPage.close();
};
return false;
},
Upvotes: 0
Reputation: 325
The reason why you are getting this violation warning is likely because the event handler doesn't return until the print page is closed. So, when you click the button the print page opens, then nothing happens until the print page is closed, then the function returns.
Upvotes: 4